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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
946 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 = {}, entity = nil)
entity ||=
2017-10-31 12:15:03 -04:00
case opts[:serializer]
2018-11-29 23:03:35 -05:00
when 'sidebar'
MergeRequestSidebarBasicEntity
2018-11-29 23:03:35 -05:00
when 'sidebar_extras'
MergeRequestSidebarExtrasEntity
when 'basic'
2017-10-31 12:15:03 -04:00
MergeRequestBasicEntity
when 'noteable'
MergeRequestNoteableEntity
when 'poll_cached_widget'
MergeRequestPollCachedWidgetEntity
when 'poll_widget'
MergeRequestPollWidgetEntity
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