Class: JSONAPI::PrimaryResourceIdTree

Inherits:
ResourceIdTree show all
Defined in:
lib/jsonapi/resource_id_tree.rb

Instance Attribute Summary

Attributes inherited from ResourceIdTree

#fragments, #related_resource_id_trees

Instance Method Summary collapse

Methods inherited from ResourceIdTree

#fetch_related_resource_id_tree

Constructor Details

#initializePrimaryResourceIdTree

Creates a PrimaryResourceIdTree with no resources and no related ResourceIdTrees



32
33
34
35
# File 'lib/jsonapi/resource_id_tree.rb', line 32

def initialize
  @fragments ||= {}
  @related_resource_id_trees ||= {}
end

Instance Method Details

#add_resource_fragment(fragment, include_related) ⇒ null

Adds a Resource Fragment to the Resources hash

Parameters:

Returns:

  • (null)


55
56
57
58
59
60
61
# File 'lib/jsonapi/resource_id_tree.rb', line 55

def add_resource_fragment(fragment, include_related)
  fragment.primary = true

  init_included_relationships(fragment, include_related)

  @fragments[fragment.identity] = fragment
end

#add_resource_fragments(fragments, include_related) ⇒ null

Adds each Resource Fragment to the Resources hash

Parameters:

  • fragments (Hash)
  • include_related (Hash)

Returns:

  • (null)


43
44
45
46
47
# File 'lib/jsonapi/resource_id_tree.rb', line 43

def add_resource_fragments(fragments, include_related)
  fragments.each_value do |fragment|
    add_resource_fragment(fragment, include_related)
  end
end