gitlab-org--gitlab-foss/app/serializers/merge_request_serializer.rb

24 lines
732 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class MergeRequestSerializer < BaseSerializer
2017-05-09 00:15:34 -04:00
# This overrided method takes care of which entity should be used
# to serialize the `merge_request` based on `serializer` key in `opts` param.
2017-05-09 00:15:34 -04:00
# Hence, `entity` doesn't need to be declared on the class scope.
def represent(merge_request, opts = {})
2017-10-31 12:15:03 -04:00
entity =
case opts[:serializer]
2018-11-29 23:03:35 -05:00
when 'sidebar'
MergeRequestSidebarBasicEntity
when 'sidebar_extras'
IssuableSidebarExtrasEntity
when 'basic'
2017-10-31 12:15:03 -04:00
MergeRequestBasicEntity
else
# fallback to widget for old poll requests without `serializer` set
MergeRequestWidgetEntity
2017-10-31 12:15:03 -04:00
end
2017-05-09 00:15:34 -04:00
super(merge_request, opts, entity)
end
end