Class: JSONAPI::RelatedResourceTree
- Inherits:
-
ResourceTree
- Object
- ResourceTree
- JSONAPI::RelatedResourceTree
- Defined in:
- lib/jsonapi/resource_tree.rb
Instance Attribute Summary collapse
-
#parent_relationship ⇒ Object
readonly
Returns the value of attribute parent_relationship.
-
#source_resource_tree ⇒ Object
readonly
Returns the value of attribute source_resource_tree.
Attributes inherited from ResourceTree
#fragments, #related_resource_trees
Instance Method Summary collapse
-
#add_resource_fragment(fragment, include_related) ⇒ null
Adds a Resource Fragment to the fragments hash.
-
#initialize(parent_relationship, source_resource_tree) ⇒ JSONAPI::RelatedResourceTree
constructor
Creates a RelatedResourceTree with no resources and no related ResourceTrees.
Methods inherited from ResourceTree
#add_resource, #add_resource_fragments, #add_resources, #get_related_resource_tree
Constructor Details
#initialize(parent_relationship, source_resource_tree) ⇒ JSONAPI::RelatedResourceTree
Creates a RelatedResourceTree with no resources and no related ResourceTrees. A connection to the parent ResourceTree is maintained.
202 203 204 205 206 207 208 209 |
# File 'lib/jsonapi/resource_tree.rb', line 202 def initialize(parent_relationship, source_resource_tree) @fragments ||= {} @related_resource_trees ||= {} @parent_relationship = parent_relationship @parent_relationship_name = parent_relationship.name.to_sym @source_resource_tree = source_resource_tree end |
Instance Attribute Details
#parent_relationship ⇒ Object (readonly)
Returns the value of attribute parent_relationship.
193 194 195 |
# File 'lib/jsonapi/resource_tree.rb', line 193 def parent_relationship @parent_relationship end |
#source_resource_tree ⇒ Object (readonly)
Returns the value of attribute source_resource_tree.
193 194 195 |
# File 'lib/jsonapi/resource_tree.rb', line 193 def source_resource_tree @source_resource_tree end |
Instance Method Details
#add_resource_fragment(fragment, include_related) ⇒ null
Adds a Resource Fragment to the fragments hash
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/jsonapi/resource_tree.rb', line 217 def add_resource_fragment(fragment, ) init_included_relationships(fragment, ) fragment..each do |rid| @source_resource_tree.fragments[rid].(parent_relationship.name, fragment.identity) end if @fragments[fragment.identity] @fragments[fragment.identity]..merge(fragment.) fragment..each_pair do |relationship_name, rids| if rids @fragments[fragment.identity].(relationship_name, rids) end end else @fragments[fragment.identity] = fragment end end |