2018-07-19 14:43:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-18 21:19:04 -05:00
|
|
|
class MergeRequestSerializer < BaseSerializer
|
2017-05-09 00:15:34 -04:00
|
|
|
# This overrided method takes care of which entity should be used
|
2017-12-07 16:56:59 -05:00
|
|
|
# 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.
|
2019-08-09 17:01:55 -04:00
|
|
|
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'
|
2019-07-25 22:30:50 -04:00
|
|
|
MergeRequestSidebarBasicEntity
|
2018-11-29 23:03:35 -05:00
|
|
|
when 'sidebar_extras'
|
2019-04-07 14:35:16 -04:00
|
|
|
MergeRequestSidebarExtrasEntity
|
2018-11-27 03:47:10 -05:00
|
|
|
when 'basic'
|
2017-10-31 12:15:03 -04:00
|
|
|
MergeRequestBasicEntity
|
2019-08-28 17:09:22 -04:00
|
|
|
when 'noteable'
|
|
|
|
MergeRequestNoteableEntity
|
2018-11-27 03:47:10 -05:00
|
|
|
else
|
|
|
|
# fallback to widget for old poll requests without `serializer` set
|
2017-12-07 16:56:59 -05:00
|
|
|
MergeRequestWidgetEntity
|
2017-10-31 12:15:03 -04:00
|
|
|
end
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
super(merge_request, opts, entity)
|
|
|
|
end
|
2016-11-18 21:19:04 -05:00
|
|
|
end
|