Module: JsonAPIObjectMapper::Deserialize::DSL::ClassMethods

Defined in:
lib/jsonapi-object-mapper/deserialize/dsl.rb

Instance Method Summary collapse

Instance Method Details

#initialize(*args) ⇒ Object



66
67
68
69
70
# File 'lib/jsonapi-object-mapper/deserialize/dsl.rb', line 66

def initialize(*args)
  @_class_attributes    = {}
  @_class_relationships = {}
  super
end

#inspectObject Also known as: to_s



80
81
82
83
84
85
# File 'lib/jsonapi-object-mapper/deserialize/dsl.rb', line 80

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)}, "\
  "@errors = #{@errors.inspect}, "\
  "attributes = #{@_class_attributes.inspect}, "\
  "relationships = #{@_class_relationships.inspect}>"
end

#to_hashObject Also known as: to_h



72
73
74
75
76
77
# File 'lib/jsonapi-object-mapper/deserialize/dsl.rb', line 72

def to_hash
  hashed_relationships = @_class_relationships.map do |key, value|
    { key => value.respond_to?(:to_hash) ? value.to_hash : value }
  end
  [@_class_attributes, *hashed_relationships].reduce({}, :merge)
end