Class: SimpleJsonapi::Node::Data::Singular
- Inherits:
-
Base
- Object
- Base
- SimpleJsonapi::Node::Data::Singular
show all
- Defined in:
- lib/simple_jsonapi/node/data/singular.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#extras, #fields_spec, #include_spec, #root_node, #serializer, #serializer_inferrer, #sort_spec
Instance Method Summary
collapse
Constructor Details
#initialize(resource:, **options) ⇒ Singular
10
11
12
13
14
15
|
# File 'lib/simple_jsonapi/node/data/singular.rb', line 10
def initialize(resource:, **options)
super(options)
@resource = resource
@resource_node = build_child_node(SimpleJsonapi::Node::Resource::Full, resource: @resource) unless @resource.nil?
end
|
Instance Attribute Details
#resource ⇒ Object
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
def initialize(resource:, **options)
super(options)
@resource = resource
@resource_node = build_child_node(SimpleJsonapi::Node::Resource::Full, resource: @resource) unless @resource.nil?
end
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
|