Class: JSONAPI::RelatedResourceIdTree
- Inherits:
-
ResourceIdTree
- Object
- ResourceIdTree
- JSONAPI::RelatedResourceIdTree
- Defined in:
- lib/jsonapi/resource_id_tree.rb
Instance Attribute Summary collapse
-
#parent_relationship ⇒ Object
readonly
Returns the value of attribute parent_relationship.
-
#source_resource_id_tree ⇒ Object
readonly
Returns the value of attribute source_resource_id_tree.
Attributes inherited from ResourceIdTree
#fragments, #related_resource_id_trees
Instance Method Summary collapse
-
#add_resource_fragment(fragment, include_related) ⇒ null
Adds a Resource Fragment to the fragments hash.
-
#add_resource_fragments(fragments, include_related) ⇒ null
Adds each Resource Fragment to the Resources hash.
-
#initialize(parent_relationship, source_resource_id_tree) ⇒ JSONAPI::RelatedResourceIdTree
constructor
Creates a RelatedResourceIdTree with no resources and no related ResourceIdTrees.
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.
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_relationship ⇒ Object (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_tree ⇒ Object (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
102 103 104 105 106 107 108 109 110 |
# File 'lib/jsonapi/resource_id_tree.rb', line 102 def add_resource_fragment(fragment, ) init_included_relationships(fragment, ) fragment..each do |rid| @source_resource_id_tree.fragments[rid].(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
90 91 92 93 94 |
# File 'lib/jsonapi/resource_id_tree.rb', line 90 def add_resource_fragments(fragments, ) fragments.each_value do |fragment| add_resource_fragment(fragment, ) end end |