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 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.
Instance Attribute Summary collapse
-
#id ⇒ Object
(also: #resource_id)
readonly
Returns the value of attribute id.
-
#type ⇒ Object
(also: #resource_type)
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.all ⇒ Resource::Token
Get the special “all” Resource Token.
Instance Method Summary collapse
-
#all? ⇒ Boolean
Test whether this token is for the special “all” Resource.
-
#all_of_type? ⇒ Boolean
Test whether this token is a wildcard for some specific type.
-
#eql?(other) ⇒ Boolean
(also: #==)
Compare with another Resource for equality.
-
#hash ⇒ Integer
Hash code based on to_s.
-
#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) Also known as: resource_id
Returns the value of attribute id.
12 13 14 |
# File 'lib/checkpoint/resource/token.rb', line 12 def id @id end |
#type ⇒ Object (readonly) Also known as: resource_type
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
#all? ⇒ Boolean
Test whether this token is for the special “all” Resource.
43 44 45 |
# File 'lib/checkpoint/resource/token.rb', line 43 def all? type == Resource::ALL && id == Resource::ALL end |
#all_of_type? ⇒ Boolean
Test whether this token is a wildcard for some specific type.
51 52 53 |
# File 'lib/checkpoint/resource/token.rb', line 51 def all_of_type? type != Resource::ALL && id == Resource::ALL end |
#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.
72 73 74 |
# File 'lib/checkpoint/resource/token.rb', line 72 def eql?(other) other.is_a?(Resource::Token) && type == other.type && id == other.id end |
#hash ⇒ Integer
Returns hash code based on to_s.
77 78 79 |
# File 'lib/checkpoint/resource/token.rb', line 77 def hash to_s.hash end |
#to_s ⇒ String
Returns a token suitable for granting or matching this resource.
66 67 68 |
# File 'lib/checkpoint/resource/token.rb', line 66 def to_s "#{type}:#{id}" end |
#token ⇒ Token
Returns self; for convenience of taking a Resource or token.
56 57 58 |
# File 'lib/checkpoint/resource/token.rb', line 56 def token self end |
#uri ⇒ String Also known as: inspect
Returns a URI for this resource, including its type and id.
61 62 63 |
# File 'lib/checkpoint/resource/token.rb', line 61 def uri "resource://#{type}/#{id}" end |