BigW Consortium Gitlab

base_serializer.rb 447 Bytes
Newer Older
1
class BaseSerializer
2 3
  def initialize(parameters = {})
    @request = EntityRequest.new(parameters)
4 5
  end

6 7 8 9
  def represent(resource, opts = {}, entity_class = nil)
    entity_class = entity_class || self.class.entity_class

    entity_class
10
      .represent(resource, opts.merge(request: @request))
11
      .as_json
12 13 14 15 16 17 18 19 20 21
  end

  def self.entity(entity_class)
    @entity_class ||= entity_class
  end

  def self.entity_class
    @entity_class
  end
end