Class: Gearhead::Serializers::FastJsonapi::ResourceSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/gearhead/serializers/fast_jsonapi/resource_serializer.rb

Class Method Summary collapse

Class Method Details

.for(page) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gearhead/serializers/fast_jsonapi/resource_serializer.rb', line 5

def self.for(page)
  klass = Class.new
  klass.include JSONAPI::Serializer
  klass.set_type page.resource.model_name.singular_route_key.to_param
  klass.attributes *(page._gear_attributes.presence || page.default_attributes)

  page._gear_custom_attributes.each do |attr, block|
    klass.attribute attr do |object|
      block.call(object)
    end
  end

  klass
end