2016-10-28 08:32:07 -04:00
|
|
|
class BaseSerializer
|
2017-10-05 05:08:05 -04:00
|
|
|
attr_reader :params
|
2017-09-07 13:08:56 -04:00
|
|
|
|
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
|
2016-11-04 10:00:39 -04:00
|
|
|
.represent(resource, opts.merge(request: @request))
|
2017-01-27 07:02:59 -05:00
|
|
|
.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
|