Class: SimpleJsonapi::Node::Resource::Linkage

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

Overview

Represents a single resource linkage object.

Instance Attribute Summary collapse

Attributes inherited from Base

#resource

Attributes inherited from Base

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

Instance Method Summary collapse

Methods inherited from Base

#resource_id, #resource_type

Constructor Details

#initialize(meta: nil, **options) ⇒ Linkage

Returns a new instance of Linkage.

Parameters:

  • meta (Hash{Symbol => Object}) (defaults to: nil)
  • options

    see Base#initialize for additional parameters



11
12
13
14
# File 'lib/simple_jsonapi/node/resource/linkage.rb', line 11

def initialize(meta: nil, **options)
  super(options)
  @meta = meta
end

Instance Attribute Details

#metaHash{Symbol => Object} (readonly)

Returns:

  • (Hash{Symbol => Object})


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/simple_jsonapi/node/resource/linkage.rb', line 6

class Linkage < Base
  attr_reader :meta

  # @param meta [Hash{Symbol => Object}]
  # @param options see {Node::Resource::Base#initialize} for additional parameters
  def initialize(meta: nil, **options)
    super(options)
    @meta = meta
  end

  # @return [Hash{Symbol => Hash}]
  def as_jsonapi
    json = {}
    json[:id] = resource_id
    json[:type] = resource_type
    json[:meta] = meta if meta.present?
    json
  end
end

Instance Method Details

#as_jsonapiHash{Symbol => Hash}

Returns:

  • (Hash{Symbol => Hash})


17
18
19
20
21
22
23
# File 'lib/simple_jsonapi/node/resource/linkage.rb', line 17

def as_jsonapi
  json = {}
  json[:id] = resource_id
  json[:type] = resource_type
  json[:meta] = meta if meta.present?
  json
end