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
|