class Checkpoint::Resource::Token

A Resource::Token is an identifier object for a Resource. It includes a type and an identifier. A {Grant} can be created for a Token. Concrete entities are resolved into a number of resources, and those resources' tokens will be checked for matching grants.

Attributes

id[R]
resource_id[R]
resource_type[R]
type[R]

Public Class Methods

all() click to toggle source

Get the special “all” Resource Token. This is a singleton that represents all resources of all types. It is used to grant permissions or roles within a zone, but not specific to a particular resource.

@return [Resource::Token] the special “all” Resource Token

# File lib/checkpoint/resource/token.rb, line 36
def self.all
  @all ||= new(Resource::ALL, Resource::ALL).freeze
end
new(type, id) click to toggle source

Create a new Resource representing a domain entity or concept that would be acted upon.

@param type [String] the application-determined type of this resource.

This might correspond to a model class or other type of named concept
in the application. The type is always coerced to String with `#to_s`
in case something else is supplied.

@param id [String] the application-resolvable identifier for this

resource. For example, this might be the ID of a model object, the
name of a section. The id is always coerced to String with `#to_s` in
case something else is supplied.
# File lib/checkpoint/resource/token.rb, line 26
def initialize(type, id)
  @type = type.to_s
  @id = id.to_s
end

Public Instance Methods

==(other)
Alias for: eql?
all?() click to toggle source

Test whether this token is for the special “all” Resource.

@return [Boolean] true if this token represents any/all resources

# File lib/checkpoint/resource/token.rb, line 43
def all?
  type == Resource::ALL && id == Resource::ALL
end
all_of_type?() click to toggle source

Test whether this token is a wildcard for some specific type.

@return [Boolean] true if this token has a specific type, but

represents any/all resources of that type
# File lib/checkpoint/resource/token.rb, line 51
def all_of_type?
  type != Resource::ALL && id == Resource::ALL
end
eql?(other) click to toggle source

Compare with another Resource for equality. Consider them to represent the same resource if `other` is a Resource, has the same type, and same id.

# File lib/checkpoint/resource/token.rb, line 72
def eql?(other)
  other.is_a?(Resource::Token) && type == other.type && id == other.id
end
Also aliased as: ==
hash() click to toggle source

@return [Integer] hash code based on to_s

# File lib/checkpoint/resource/token.rb, line 77
def hash
  to_s.hash
end
inspect()
Alias for: uri
to_s() click to toggle source

@return [String] a token suitable for granting or matching this resource

# File lib/checkpoint/resource/token.rb, line 66
def to_s
  "#{type}:#{id}"
end
token() click to toggle source

@return [Token] self; for convenience of taking a Resource or token

# File lib/checkpoint/resource/token.rb, line 56
def token
  self
end
uri() click to toggle source

@return [String] a URI for this resource, including its type and id

# File lib/checkpoint/resource/token.rb, line 61
def uri
  "resource://#{type}/#{id}"
end
Also aliased as: inspect