Class: JSONAPI::RelatedResourceIdTree

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

Instance Attribute Summary collapse

Attributes inherited from ResourceIdTree

#fragments, #related_resource_id_trees

Instance Method Summary collapse

Methods inherited from ResourceIdTree

#fetch_related_resource_id_tree

Constructor Details

#initialize(parent_relationship, source_resource_id_tree) ⇒ JSONAPI::RelatedResourceIdTree

Creates a RelatedResourceIdTree with no resources and no related ResourceIdTrees. A connection to the parent ResourceIdTree is maintained.

Parameters:



75
76
77
78
79
80
81
82
# File 'lib/jsonapi/resource_id_tree.rb', line 75

def initialize(parent_relationship, source_resource_id_tree)
  @fragments ||= {}
  @related_resource_id_trees ||= {}

  @parent_relationship = parent_relationship
  @parent_relationship_name = parent_relationship.name.to_sym
  @source_resource_id_tree = source_resource_id_tree
end

Instance Attribute Details

#parent_relationshipObject (readonly)

Returns the value of attribute parent_relationship.



66
67
68
# File 'lib/jsonapi/resource_id_tree.rb', line 66

def parent_relationship
  @parent_relationship
end

#source_resource_id_treeObject (readonly)

Returns the value of attribute source_resource_id_tree.



66
67
68
# File 'lib/jsonapi/resource_id_tree.rb', line 66

def source_resource_id_tree
  @source_resource_id_tree
end

Instance Method Details

#add_resource_fragment(fragment, include_related) ⇒ null

Adds a Resource Fragment to the fragments hash

Parameters:

Returns:

  • (null)


102
103
104
105
106
107
108
109
110
# File 'lib/jsonapi/resource_id_tree.rb', line 102

def add_resource_fragment(fragment, include_related)
  init_included_relationships(fragment, include_related)

  fragment.related_from.each do |rid|
    @source_resource_id_tree.fragments[rid].add_related_identity(parent_relationship.name, fragment.identity)
  end

  @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)


90
91
92
93
94
# File 'lib/jsonapi/resource_id_tree.rb', line 90

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