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

32 lines
1,014 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.
2019-10-12 21:52:04 +05:30
def represent(merge_request, opts = {}, entity = nil)
entity ||=
2018-03-17 18:26:18 +05:30
case opts[:serializer]
2019-02-15 15:39:39 +05:30
when 'sidebar'
2019-12-04 20:38:33 +05:30
MergeRequestSidebarBasicEntity
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-12-04 20:38:33 +05:30
when 'noteable'
MergeRequestNoteableEntity
2020-04-22 19:07:51 +05:30
when 'poll_cached_widget'
MergeRequestPollCachedWidgetEntity
when 'poll_widget'
MergeRequestPollWidgetEntity
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
2020-05-24 23:13:21 +05:30
MergeRequestSerializer.prepend_if_ee('EE::MergeRequestSerializer')