blob: 4744a7c1cc859cc065c8085aaf83ad28922578a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# frozen_string_literal: true
class BaseSerializer
attr_reader :params
def initialize(params = {})
@params = params
@request = EntityRequest.new(params)
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
class << self
attr_reader :entity_class
def entity(entity_class)
@entity_class ||= entity_class
end
end
end
|