Class: SimpleJsonapi::Node::Data::Singular
- Defined in:
- lib/simple_jsonapi/node/data/singular.rb
Instance Attribute Summary collapse
- #resource ⇒ Object readonly
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.
10 11 12 13 14 15 |
# File 'lib/simple_jsonapi/node/data/singular.rb', line 10 def initialize(resource:, **) super() @resource = resource @resource_node = build_child_node(SimpleJsonapi::Node::Resource::Full, resource: @resource) unless @resource.nil? end |
Instance Attribute Details
#resource ⇒ Object (readonly)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/simple_jsonapi/node/data/singular.rb', line 5 class Singular < SimpleJsonapi::Node::Base attr_reader :resource # @param resource [Object] # @param options see {Node::Base#initialize} for additional parameters def initialize(resource:, **) super() @resource = resource @resource_node = build_child_node(SimpleJsonapi::Node::Resource::Full, resource: @resource) unless @resource.nil? end # @return [Hash{Symbol => Hash}] def as_jsonapi if resource.nil? { data: nil } else { data: @resource_node.as_jsonapi } end end end |
Instance Method Details
#as_jsonapi ⇒ Hash{Symbol => Hash}
18 19 20 21 22 23 24 |
# File 'lib/simple_jsonapi/node/data/singular.rb', line 18 def as_jsonapi if resource.nil? { data: nil } else { data: @resource_node.as_jsonapi } end end |