Class: JSONAPI::PrimaryResourceTree
- Inherits:
-
ResourceTree
- Object
- ResourceTree
- JSONAPI::PrimaryResourceTree
- Defined in:
- lib/jsonapi/resource_tree.rb
Instance Attribute Summary
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.
- #complete_includes!(include_related, options) ⇒ Object
-
#initialize(fragments: nil, resources: nil, resource: nil, include_related: nil, options: nil) ⇒ PrimaryResourceTree
constructor
Creates a PrimaryResourceTree 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(fragments: nil, resources: nil, resource: nil, include_related: nil, options: nil) ⇒ PrimaryResourceTree
Creates a PrimaryResourceTree with no resources and no related ResourceTrees
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/jsonapi/resource_tree.rb', line 149 def initialize(fragments: nil, resources: nil, resource: nil, include_related: nil, options: nil) @fragments ||= {} @related_resource_trees ||= {} if fragments || resources || resource if fragments add_resource_fragments(fragments, ) end if resources add_resources(resources, ) end if resource add_resource(resource, ) end complete_includes!(, ) end end |
Instance Method Details
#add_resource_fragment(fragment, include_related) ⇒ null
Adds a Resource Fragment to the fragments hash
175 176 177 178 |
# File 'lib/jsonapi/resource_tree.rb', line 175 def add_resource_fragment(fragment, ) fragment.primary = true super(fragment, ) end |
#complete_includes!(include_related, options) ⇒ Object
180 181 182 183 184 185 186 187 188 |
# File 'lib/jsonapi/resource_tree.rb', line 180 def complete_includes!(, ) # ToDo: can we skip if more than one resource_klass found? resource_klasses = Set.new @fragments.each_key { |identity| resource_klasses << identity.resource_klass } resource_klasses.each { |resource_klass| load_included(resource_klass, self, , )} self end |