Class: SimpleJsonapi::Node::RelationshipData::Singular
- Defined in:
- lib/simple_jsonapi/node/relationship_data/singular.rb
Overview
Represents a relationship’s data
object containing a single resource linkage object.
Instance Attribute Summary collapse
- #resource ⇒ Object readonly
Attributes inherited from Base
#add_to_included, #relationship_definition
Attributes inherited from Base
#extras, #fields_spec, #include_spec, #root_node, #serializer, #serializer_inferrer, #sort_spec
Instance Method Summary collapse
- #as_jsonapi ⇒ Hash{Symbol => Hash}
-
#initialize(resource:, **options) ⇒ Singular
constructor
A new instance of Singular.
Constructor Details
#initialize(resource:, **options) ⇒ Singular
Returns a new instance of Singular.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/simple_jsonapi/node/relationship_data/singular.rb', line 12 def initialize(resource:, **) super @resource = resource unless @resource.nil? @linkage_node = build_linkage_node(@resource) add_resource_to_included(@resource, @linkage_node) end end |
Instance Attribute Details
#resource ⇒ Object (readonly)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/simple_jsonapi/node/relationship_data/singular.rb', line 7 class Singular < Base attr_reader :resource # @param resource [Object] # @param options see {Node::RelationshipData::Base#initialize} for additional parameters def initialize(resource:, **) super @resource = resource unless @resource.nil? @linkage_node = build_linkage_node(@resource) add_resource_to_included(@resource, @linkage_node) end end # @return [Hash{Symbol => Hash}] def as_jsonapi if resource.nil? { data: nil } else { data: @linkage_node.as_jsonapi } end end end |
Instance Method Details
#as_jsonapi ⇒ Hash{Symbol => Hash}
25 26 27 28 29 30 31 |
# File 'lib/simple_jsonapi/node/relationship_data/singular.rb', line 25 def as_jsonapi if resource.nil? { data: nil } else { data: @linkage_node.as_jsonapi } end end |