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

27 lines
519 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 BaseSerializer
2018-03-17 18:26:18 +05:30
attr_reader :params
def initialize(params = {})
@params = params
@request = EntityRequest.new(params)
2017-08-17 22:00:37 +05:30
end
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
end
2019-03-02 22:35:43 +05:30
class << self
attr_reader :entity_class
2017-08-17 22:00:37 +05:30
2019-03-02 22:35:43 +05:30
def entity(entity_class)
@entity_class ||= entity_class
end
2017-08-17 22:00:37 +05:30
end
end