class JSONAPI::RelatedResourceIdTree
Attributes
parent_relationship[R]
source_resource_id_tree[R]
Public Class Methods
new(parent_relationship, source_resource_id_tree)
click to toggle source
Creates a RelatedResourceIdTree
with no resources and no related ResourceIdTrees. A connection to the parent ResourceIdTree
is maintained.
@param parent_relationship
[JSONAPI::Relationship] @param source_resource_id_tree
[JSONAPI::ResourceIdTree]
@return [JSONAPI::RelatedResourceIdTree] the new or existing resource id tree for the requested relationship
# 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
Public Instance Methods
add_resource_fragment(fragment, include_related)
click to toggle source
Adds a Resource
Fragment to the fragments hash
@param fragment [JSONAPI::ResourceFragment] @param include_related [Hash]
@return [null]
# 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)
click to toggle source
Adds each Resource
Fragment to the Resources
hash
@param fragments [Hash] @param include_related [Hash]
@return [null]
# 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