Class: SimpleJsonapi::Node::RelationshipData::Base Abstract
- Defined in:
- lib/simple_jsonapi/node/relationship_data/base.rb
Overview
This class is abstract.
Represents a relationship’s data
object.
Direct Known Subclasses
Instance Attribute Summary collapse
Attributes inherited from Base
#extras, #fields_spec, #include_spec, #root_node, #serializer, #serializer_inferrer, #sort_spec
Instance Method Summary collapse
-
#initialize(relationship_definition:, add_to_included:, **options) ⇒ Base
constructor
A new instance of Base.
Methods inherited from Base
Constructor Details
#initialize(relationship_definition:, add_to_included:, **options) ⇒ Base
Returns a new instance of Base.
15 16 17 18 19 20 21 22 23 |
# File 'lib/simple_jsonapi/node/relationship_data/base.rb', line 15 def initialize(relationship_definition:, add_to_included:, **) super() @relationship_definition = relationship_definition @add_to_included = add_to_included @serializer_inferrer = relationship_definition.serializer_inferrer @include_spec = include_spec[relationship_name] end |
Instance Attribute Details
#add_to_included ⇒ Boolean (readonly)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/simple_jsonapi/node/relationship_data/base.rb', line 9 class Base < SimpleJsonapi::Node::Base attr_reader :relationship_definition, :add_to_included # @param relationship_definition [Definition::Relationship] # @param add_to_included [Boolean] # @param options see {Node::Base#initialize} for additional parameters def initialize(relationship_definition:, add_to_included:, **) super() @relationship_definition = relationship_definition @add_to_included = add_to_included @serializer_inferrer = relationship_definition.serializer_inferrer @include_spec = include_spec[relationship_name] end private def build_linkage_node() build_child_node( SimpleJsonapi::Node::Resource::Linkage, resource: , meta: { included: add_to_included }, ) end def add_resource_to_included(, linkage_node) if add_to_included && !root_node.included_resource?(linkage_node) full_node = build_child_node( SimpleJsonapi::Node::Resource::Full, # Only support sorting on first-level relationships because # 1. supporting more levels requires more tracking of how the document is being built # 2. letting the API client sort a deeper relationship seems unnecessary sort_related: nil, resource: , ) root_node.append_included_resource(full_node) end end def relationship_name relationship_definition.name end end |
#relationship_definition ⇒ Definition::Relationship (readonly)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/simple_jsonapi/node/relationship_data/base.rb', line 9 class Base < SimpleJsonapi::Node::Base attr_reader :relationship_definition, :add_to_included # @param relationship_definition [Definition::Relationship] # @param add_to_included [Boolean] # @param options see {Node::Base#initialize} for additional parameters def initialize(relationship_definition:, add_to_included:, **) super() @relationship_definition = relationship_definition @add_to_included = add_to_included @serializer_inferrer = relationship_definition.serializer_inferrer @include_spec = include_spec[relationship_name] end private def build_linkage_node() build_child_node( SimpleJsonapi::Node::Resource::Linkage, resource: , meta: { included: add_to_included }, ) end def add_resource_to_included(, linkage_node) if add_to_included && !root_node.included_resource?(linkage_node) full_node = build_child_node( SimpleJsonapi::Node::Resource::Full, # Only support sorting on first-level relationships because # 1. supporting more levels requires more tracking of how the document is being built # 2. letting the API client sort a deeper relationship seems unnecessary sort_related: nil, resource: , ) root_node.append_included_resource(full_node) end end def relationship_name relationship_definition.name end end |