Class: SimpleJsonapi::Node::Resource::Base

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_jsonapi/node/resource/base.rb

Overview

Represents a single resource object or resource linkage object.

Direct Known Subclasses

Full, Linkage

Instance Attribute Summary collapse

Attributes inherited from Base

#extras, #fields_spec, #include_spec, #root_node, #serializer, #serializer_inferrer, #sort_spec

Instance Method Summary collapse

Methods inherited from Base

#as_jsonapi

Constructor Details

#initialize(resource:, **options) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
# File 'lib/simple_jsonapi/node/resource/base.rb', line 6

def initialize(resource:, **options)
  super(options)

  @resource = resource
  @serializer = serializer_inferrer.infer(resource).new
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'lib/simple_jsonapi/node/resource/base.rb', line 4

def resource
  @resource
end

Instance Method Details

#resource_idObject



13
14
15
# File 'lib/simple_jsonapi/node/resource/base.rb', line 13

def resource_id
  @resource_id ||= evaluate(serializer.id_definition, resource).to_s
end

#resource_typeObject



17
18
19
# File 'lib/simple_jsonapi/node/resource/base.rb', line 17

def resource_type
  @resource_type ||= evaluate(serializer.type_definition, resource).to_s
end