Module: Quiver::Serialization::JsonApi::Serializer::ClassMethods

Defined in:
lib/quiver/serialization/json_api/serializer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#type_handlersObject

Returns the value of attribute type_handlers.



61
62
63
# File 'lib/quiver/serialization/json_api/serializer.rb', line 61

def type_handlers
  @type_handlers
end

Class Method Details

.extended(base) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/quiver/serialization/json_api/serializer.rb', line 49

def self.extended(base)
  base.instance_variable_set('@type_handlers', {})

  begin
    base.for_type 'Error', JsonApi::ItemTypeHandler.new('Error', -> {
      attributes :title, :detail, :path, :code
      calculated_attribute(:status) { |item| item.status.to_s }
    }, true)
  rescue JsonApi::NoIdError
  end
end

Instance Method Details

#for_type(type, handler = nil, &block) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/quiver/serialization/json_api/serializer.rb', line 63

def for_type(type, handler=nil, &block)
  if handler
    type_handlers[type] = handler
  else
    type_handlers[type] = JsonApi::ItemTypeHandler.new(type, block)
  end
end