debian-mirror-gitlab/app/serializers/merge_request_serializer.rb

24 lines
732 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class MergeRequestSerializer < BaseSerializer
# This overrided method takes care of which entity should be used
2018-03-17 18:26:18 +05:30
# to serialize the `merge_request` based on `serializer` key in `opts` param.
2017-08-17 22:00:37 +05:30
# Hence, `entity` doesn't need to be declared on the class scope.
def represent(merge_request, opts = {})
2018-03-17 18:26:18 +05:30
entity =
case opts[:serializer]
2019-02-15 15:39:39 +05:30
when 'sidebar'
2019-07-31 22:56:46 +05:30
IssuableSidebarBasicEntity
2019-02-15 15:39:39 +05:30
when 'sidebar_extras'
2019-07-31 22:56:46 +05:30
MergeRequestSidebarExtrasEntity
2019-02-15 15:39:39 +05:30
when 'basic'
2018-03-17 18:26:18 +05:30
MergeRequestBasicEntity
2019-02-15 15:39:39 +05:30
else
# fallback to widget for old poll requests without `serializer` set
2018-03-17 18:26:18 +05:30
MergeRequestWidgetEntity
end
2017-08-17 22:00:37 +05:30
super(merge_request, opts, entity)
end
end