Class: JSONAPI::ResourceIdentity
- Inherits:
-
Object
- Object
- JSONAPI::ResourceIdentity
- Defined in:
- lib/jsonapi/resource_identity.rb
Overview
ResourceIdentity describes a unique identity of a resource in the system. This consists of a Resource class and an identifier that is unique within that Resource class. ResourceIdentities are intended to be used as hash keys to provide ordered mixing of resource types in result sets.
Creating a ResourceIdentity
rid = ResourceIdentity.new(PostResource, 12)
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#resource_klass ⇒ Object
readonly
Returns the value of attribute resource_klass.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(resource_klass, id) ⇒ ResourceIdentity
constructor
A new instance of ResourceIdentity.
-
#to_s ⇒ Object
Creates a string representation of the identifier.
Constructor Details
#initialize(resource_klass, id) ⇒ ResourceIdentity
Returns a new instance of ResourceIdentity.
16 17 18 19 |
# File 'lib/jsonapi/resource_identity.rb', line 16 def initialize(resource_klass, id) @resource_klass = resource_klass @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/jsonapi/resource_identity.rb', line 14 def id @id end |
#resource_klass ⇒ Object (readonly)
Returns the value of attribute resource_klass.
14 15 16 |
# File 'lib/jsonapi/resource_identity.rb', line 14 def resource_klass @resource_klass end |
Instance Method Details
#==(other) ⇒ Object
21 22 23 24 25 |
# File 'lib/jsonapi/resource_identity.rb', line 21 def ==(other) # :nocov: eql?(other) # :nocov: end |
#eql?(other) ⇒ Boolean
27 28 29 |
# File 'lib/jsonapi/resource_identity.rb', line 27 def eql?(other) other.is_a?(ResourceIdentity) && other.resource_klass == @resource_klass && other.id == @id end |
#hash ⇒ Object
31 32 33 |
# File 'lib/jsonapi/resource_identity.rb', line 31 def hash [@resource_klass, @id].hash end |
#to_s ⇒ Object
Creates a string representation of the identifier.
36 37 38 39 40 |
# File 'lib/jsonapi/resource_identity.rb', line 36 def to_s # :nocov: "#{resource_klass}:#{id}" # :nocov: end |