summaryrefslogtreecommitdiff
path: root/app/serializers/base_serializer.rb
blob: 4e6c15f673b00e7907adf24d1b657725303b236b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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