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

25 lines
483 B
Ruby
Raw Normal View History

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
def self.entity(entity_class)
@entity_class ||= entity_class
end
def self.entity_class
@entity_class
end
end