Class: SimpleJsonapi::Node::Resource::Full
- Defined in:
- lib/simple_jsonapi/node/resource/full.rb
Overview
Represents a single resource object.
Instance Attribute Summary
Attributes inherited from Base
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(**options) ⇒ Full
constructor
A new instance of Full.
Methods inherited from Base
Constructor Details
#initialize(**options) ⇒ Full
Returns a new instance of Full.
5 6 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 33 |
# File 'lib/simple_jsonapi/node/resource/full.rb', line 5 def initialize(**) super() @attributes_node = build_child_node( SimpleJsonapi::Node::Attributes, resource: resource, resource_type: resource_type, attribute_definitions: serializer.attribute_definitions, ) @relationships_node = build_child_node( SimpleJsonapi::Node::Relationships, resource: resource, resource_type: resource_type, relationship_definitions: serializer.relationship_definitions, ) @links_node = build_child_node( SimpleJsonapi::Node::ObjectLinks, object: resource, link_definitions: serializer.link_definitions, ) @meta_node = build_child_node( SimpleJsonapi::Node::ObjectMeta, object: resource, meta_definitions: serializer., ) end |
Instance Method Details
#as_jsonapi ⇒ Hash{Symbol => Hash}
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/simple_jsonapi/node/resource/full.rb', line 36 def as_jsonapi json = {} json[:id] = resource_id json[:type] = resource_type json.merge!(@attributes_node.as_jsonapi) json.merge!(@relationships_node.as_jsonapi) json.merge!(@links_node.as_jsonapi) json.merge!(@meta_node.as_jsonapi) json end |