class JSONAPI::ResourceIdentity

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)

Attributes

id[R]
resource_klass[R]

Public Class Methods

new(resource_klass, id) click to toggle source
# File lib/jsonapi/resource_identity.rb, line 16
def initialize(resource_klass, id)
  @resource_klass = resource_klass
  @id = id
end

Public Instance Methods

==(other) click to toggle source
# File lib/jsonapi/resource_identity.rb, line 21
def ==(other)
  # :nocov:
  eql?(other)
  # :nocov:
end
eql?(other) click to toggle source
# 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() click to toggle source
# File lib/jsonapi/resource_identity.rb, line 31
def hash
  [@resource_klass, @id].hash
end
to_s() click to toggle source

Creates a string representation of the identifier.

# File lib/jsonapi/resource_identity.rb, line 36
def to_s
  # :nocov:
  "#{resource_klass}:#{id}"
  # :nocov:
end