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

27 lines
519 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-10-28 08:32:07 -04:00
class BaseSerializer
2017-10-05 05:08:05 -04:00
attr_reader :params
2017-10-05 05:08:05 -04:00
def initialize(params = {})
@params = params
@request = EntityRequest.new(params)
2016-10-28 08:32:07 -04:00
end
2017-05-09 00:15:34 -04:00
def represent(resource, opts = {}, entity_class = nil)
entity_class = entity_class || self.class.entity_class
entity_class
.represent(resource, opts.merge(request: @request))
.as_json
2016-10-28 08:32:07 -04:00
end
class << self
attr_reader :entity_class
2016-10-28 08:32:07 -04:00
def entity(entity_class)
@entity_class ||= entity_class
end
2016-10-28 08:32:07 -04:00
end
end