Class: Checkpoint::Resource::Token
- Inherits:
-
Object
- Object
- Checkpoint::Resource::Token
- Defined in:
- lib/checkpoint/resource/token.rb
Overview
A Resource::Token is an identifier object for a Resource. It includes a type and an identifier. A Permit can be granted for a Token. Concrete entities are resolved into a number of resources, and those resources’ tokens will be checked for matching permits.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.all ⇒ Resource::Token
Get the special “all” Resource Token.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
Compare with another Resource for equality.
-
#initialize(type, id) ⇒ Token
constructor
Create a new Resource representing a domain entity or concept that would be acted upon.
-
#to_s ⇒ String
A token suitable for granting or matching this resource.
-
#token ⇒ Token
Self; for convenience of taking a Resource or token.
-
#uri ⇒ String
(also: #inspect)
A URI for this resource, including its type and id.
Constructor Details
#initialize(type, id) ⇒ Token
Create a new Resource representing a domain entity or concept that would be acted upon.
26 27 28 29 |
# File 'lib/checkpoint/resource/token.rb', line 26 def initialize(type, id) @type = type.to_s @id = id.to_s end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/checkpoint/resource/token.rb', line 12 def id @id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
12 13 14 |
# File 'lib/checkpoint/resource/token.rb', line 12 def type @type end |
Class Method Details
.all ⇒ Resource::Token
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.
36 37 38 |
# File 'lib/checkpoint/resource/token.rb', line 36 def self.all @all ||= new(Resource::ALL, Resource::ALL).freeze end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
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.
57 58 59 |
# File 'lib/checkpoint/resource/token.rb', line 57 def eql?(other) other.is_a?(Resource::Token) && type == other.type && id == other.id end |
#to_s ⇒ String
Returns a token suitable for granting or matching this resource.
51 52 53 |
# File 'lib/checkpoint/resource/token.rb', line 51 def to_s "#{type}:#{id}" end |
#token ⇒ Token
Returns self; for convenience of taking a Resource or token.
41 42 43 |
# File 'lib/checkpoint/resource/token.rb', line 41 def token self end |
#uri ⇒ String Also known as: inspect
Returns a URI for this resource, including its type and id.
46 47 48 |
# File 'lib/checkpoint/resource/token.rb', line 46 def uri "resource://#{type}/#{id}" end |