Class: FastSerializer::JsonModel::Object

Inherits:
Node
  • Object
show all
Defined in:
lib/fast_serializer/json_model/object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#injectable?

Constructor Details

#initializeObject

Returns a new instance of Object.



7
8
9
10
# File 'lib/fast_serializer/json_model/object.rb', line 7

def initialize
  super
  @attributes = {}
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



5
6
7
# File 'lib/fast_serializer/json_model/object.rb', line 5

def attributes
  @attributes
end

Instance Method Details

#add_attribute(attribute) ⇒ Object

Parameters:



13
14
15
# File 'lib/fast_serializer/json_model/object.rb', line 13

def add_attribute(attribute)
  attributes[attribute.key] = attribute
end

#included?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/fast_serializer/json_model/object.rb', line 37

def included?(*)
  true
end

#serialize(resource, params, context) ⇒ Hash

Parameters:

  • resource (Object)
  • params (Hash)
  • context (Hash)

Returns:

  • (Hash)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fast_serializer/json_model/object.rb', line 21

def serialize(resource, params, context)
  return if !resource

  result = {}

  attributes.each do |_, attribute|
    next unless attribute.included?(resource, params, context)

    val = attribute.serialize(resource, params, context)
    result[attribute.key] = val
  end

  result
end