Sha256: e91d4e0c607e0c89e674092605dca9072f8e0d8cdd7896520acea6f452d0cb3e

Contents?: true

Size: 994 Bytes

Versions: 18

Compression:

Stored size: 994 Bytes

Contents

module JSONAPI

  # 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)
  #
  class ResourceIdentity
    attr_reader :resource_klass, :id

    def initialize(resource_klass, id)
      @resource_klass = resource_klass
      @id = id
    end

    def ==(other)
      # :nocov:
      eql?(other)
      # :nocov:
    end

    def eql?(other)
      other.is_a?(ResourceIdentity) && other.resource_klass == @resource_klass && other.id == @id
    end

    def hash
      [@resource_klass, @id].hash
    end

    # Creates a string representation of the identifier.
    def to_s
      # :nocov:
      "#{resource_klass}:#{id}"
      # :nocov:
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
jsonapi-resources-0.10.7 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.6 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.5 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.4 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.3 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.2 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.1 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.0 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.0.beta9 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.0.beta8 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.0.beta7 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.0.beta6 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.0.beta5 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.0.beta4 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.0.beta3 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.0.beta2.1 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.0.beta2 lib/jsonapi/resource_identity.rb
jsonapi-resources-0.10.0.beta1 lib/jsonapi/resource_identity.rb