Class: Checkpoint::Resource::Token

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/checkpoint/resource/token.rb', line 12

def id
  @id
end

#typeObject (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

.allResource::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

#hashInteger



62
63
64
# File 'lib/checkpoint/resource/token.rb', line 62

def hash
  to_s.hash
end

#to_sString



51
52
53
# File 'lib/checkpoint/resource/token.rb', line 51

def to_s
  "#{type}:#{id}"
end

#tokenToken



41
42
43
# File 'lib/checkpoint/resource/token.rb', line 41

def token
  self
end

#uriString Also known as: inspect



46
47
48
# File 'lib/checkpoint/resource/token.rb', line 46

def uri
  "resource://#{type}/#{id}"
end