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

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