Class: JSONAPI::Document::ResourceId
- Inherits:
-
Object
- Object
- JSONAPI::Document::ResourceId
- Defined in:
- lib/easy/jsonapi/document/resource_id.rb
Overview
A jsonapi resource identifier
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type:, id:) ⇒ ResourceId
constructor
A new instance of ResourceId.
-
#to_h ⇒ Object
Represents ResourceID as a jsonapi hash.
-
#to_s ⇒ Object
Represents ResourceId as a JSON parsable string.
Constructor Details
#initialize(type:, id:) ⇒ ResourceId
Returns a new instance of ResourceId.
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
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/easy/jsonapi/document/resource_id.rb', line 8 def id @id end |
#type ⇒ Object
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_h ⇒ Object
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_s ⇒ Object
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 |