debian-mirror-gitlab/app/serializers/base_serializer.rb
2017-08-17 22:00:37 +05:30

21 lines
447 B
Ruby

class BaseSerializer
def initialize(parameters = {})
@request = EntityRequest.new(parameters)
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
def self.entity(entity_class)
@entity_class ||= entity_class
end
def self.entity_class
@entity_class
end
end