Class: JSONAPI::Document::ResourceId

Inherits:
Object
  • Object
show all
Defined in:
lib/easy/jsonapi/document/resource_id.rb

Overview

A jsonapi resource identifier

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, id:) ⇒ ResourceId

Returns a new instance of ResourceId.

Parameters:

  • type (String | Symbol)

    The type of the resource identifier

  • id (String | Symbol)

    The id of the resource identifier



12
13
14
15
# File 'lib/easy/jsonapi/document/resource_id.rb', line 12

def initialize(type:, id:)
  @type = type.to_s
  @id = id.to_s
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/easy/jsonapi/document/resource_id.rb', line 8

def id
  @id
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/easy/jsonapi/document/resource_id.rb', line 8

def type
  @type
end

Instance Method Details

#to_hObject

Represents ResourceID as a jsonapi hash



23
24
25
# File 'lib/easy/jsonapi/document/resource_id.rb', line 23

def to_h
  { type: @type, id: @id }
end

#to_sObject

Represents ResourceId as a JSON parsable string



18
19
20
# File 'lib/easy/jsonapi/document/resource_id.rb', line 18

def to_s
  "{ \"type\": \"#{@type}\", \"id\": \"#{@id}\" }"
end