Class: Checkpoint::Agent
- Inherits:
-
Object
- Object
- Checkpoint::Agent
- Defined in:
- lib/checkpoint/agent.rb,
lib/checkpoint/agent/token.rb,
lib/checkpoint/agent/resolver.rb
Overview
An Agent is an any person or entity that might be granted various permission, such as a user, group, or institution.
The application objects that an agent represents may be of any type; this is more of an interface or role than a base class. The important concept is that permits are granted to agents, and that agents may be representative of multiple concrete actors, such as any person affiliated with a given institution or any member of a given group.
Defined Under Namespace
Instance Attribute Summary collapse
-
#actor ⇒ Object
Returns the value of attribute actor.
Class Method Summary collapse
-
.from(actor) ⇒ Agent
Default conversion from an actor to an Agent.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Check whether two Agents refer to the same concrete actor.
-
#eql?(other) ⇒ Boolean
Check whether two Agents refer to the same concrete actor.
-
#id ⇒ String
Get the captive actor’s id.
-
#initialize(actor) ⇒ Agent
constructor
Create an Agent.
- #token ⇒ Object
-
#type ⇒ String
Get the captive actor’s type.
Constructor Details
#initialize(actor) ⇒ Agent
Create an Agent. This should not be called externally; use from instead.
19 20 21 |
# File 'lib/checkpoint/agent.rb', line 19 def initialize(actor) @actor = actor end |
Instance Attribute Details
#actor ⇒ Object
Returns the value of attribute actor.
16 17 18 |
# File 'lib/checkpoint/agent.rb', line 16 def actor @actor end |
Class Method Details
.from(actor) ⇒ Agent
Default conversion from an actor to an Checkpoint::Agent.
If the actor implements #to_agent, we will delegate to it. Otherwise, we check if the actor implements #agent_type or #agent_id; if so, we use them as the type and id, respectively. If not, we use the actor’s class name as the type and call #id for the id. If the actor does not implement any of the ways to supply an #id, an error will be raised.
32 33 34 35 36 37 38 |
# File 'lib/checkpoint/agent.rb', line 32 def self.from(actor) if actor.respond_to?(:to_agent) actor.to_agent else new(actor) end end |
Instance Method Details
#==(other) ⇒ Boolean
Check whether two Agents refer to the same concrete actor.
89 90 91 |
# File 'lib/checkpoint/agent.rb', line 89 def ==(other) other.is_a?(Agent) && actor == other.actor end |
#eql?(other) ⇒ Boolean
Check whether two Agents refer to the same concrete actor.
81 82 83 |
# File 'lib/checkpoint/agent.rb', line 81 def eql?(other) other.is_a?(Agent) && actor.eql?(other.actor) end |
#id ⇒ String
Get the captive actor’s id.
If the entity implements ‘#to_agent`, we will call that and use the returned agent’s id. If not, but it implements ‘#agent_id`, we will use that. Otherwise, we call `#id`. If the the actor does not implement any of these methods, we raise a NoIdentifierError.
63 64 65 66 67 68 69 70 71 |
# File 'lib/checkpoint/agent.rb', line 63 def id if actor.respond_to?(:agent_id) actor.agent_id elsif actor.respond_to?(:id) actor.id else raise NoIdentifierError, "No usable identifier on actor of type: #{actor.class}" end.to_s end |
#token ⇒ Object
73 74 75 |
# File 'lib/checkpoint/agent.rb', line 73 def token @token ||= Token.new(type, id) end |
#type ⇒ String
Get the captive actor’s type.
If the entity implements ‘#to_agent`, we will call that and use the returned agent’s type. If not, but it implements ‘#agent_type`, we will use that. Otherwise, we use the actors’s class name.
47 48 49 50 51 52 53 |
# File 'lib/checkpoint/agent.rb', line 47 def type if actor.respond_to?(:agent_type) actor.agent_type else actor.class end.to_s end |