module Quiver::Serialization::JsonApi::Serializer::ClassMethods

Attributes

type_handlers[RW]

Public Class Methods

extended(base) click to toggle source
# 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

Public Instance Methods

for_type(type, handler=nil, &block) click to toggle source
# 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