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.
18 19 20 21 |
# File 'lib/jsonapi/resource_identity.rb', line 18 def initialize(resource_klass, id) @resource_klass = resource_klass @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
16 17 18 |
# File 'lib/jsonapi/resource_identity.rb', line 16 def id @id end |
#resource_klass ⇒ Object (readonly)
Returns the value of attribute resource_klass.
16 17 18 |
# File 'lib/jsonapi/resource_identity.rb', line 16 def resource_klass @resource_klass end |
Instance Method Details
#==(other) ⇒ Object
23 24 25 26 27 |
# File 'lib/jsonapi/resource_identity.rb', line 23 def ==(other) # :nocov: eql?(other) # :nocov: end |
#eql?(other) ⇒ Boolean
29 30 31 |
# File 'lib/jsonapi/resource_identity.rb', line 29 def eql?(other) other.is_a?(ResourceIdentity) && other.resource_klass == @resource_klass && other.id == @id end |
#hash ⇒ Object
33 34 35 |
# File 'lib/jsonapi/resource_identity.rb', line 33 def hash [@resource_klass, @id].hash end |
#to_s ⇒ Object
Creates a string representation of the identifier.
38 39 40 41 42 |
# File 'lib/jsonapi/resource_identity.rb', line 38 def to_s # :nocov: "#{resource_klass}:#{id}" # :nocov: end |