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 credentials, 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 credentials 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.
In an application, agents will typically be created by the Resolver registered with an Authority. This keeps most of the application code decoupled from the Agent type, allowing the binding to happen in an isolated component. It will also generally not be required to subclass Agent, since it delegates to the concrete actor in flexible, well-defined ways, detailed on the individual methods here.
Defined Under Namespace
Instance Attribute Summary collapse
-
#actor ⇒ Object
Returns the value of attribute actor.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Check whether two Agents refer to the same concrete actor by type and id.
-
#eql?(other) ⇒ Boolean
Check whether two Agents refer to the same concrete actor.
-
#id ⇒ String
Get the wrapped actor’s ID.
-
#initialize(actor) ⇒ Agent
constructor
Create an Agent, wrapping a concrete actor.
-
#to_agent ⇒ Object
Convert this object to an Agent.
- #token ⇒ Object
-
#type ⇒ String
Get the wrapped actor’s type.
Constructor Details
Instance Attribute Details
#actor ⇒ Object
Returns the value of attribute actor.
23 24 25 |
# File 'lib/checkpoint/agent.rb', line 23 def actor @actor end |
Instance Method Details
#==(other) ⇒ Boolean
Check whether two Agents refer to the same concrete actor by type and id.
90 91 92 |
# File 'lib/checkpoint/agent.rb', line 90 def ==(other) other.is_a?(Agent) && type == other.type && id == other.id end |
#eql?(other) ⇒ Boolean
Check whether two Agents refer to the same concrete actor.
83 84 85 |
# File 'lib/checkpoint/agent.rb', line 83 def eql?(other) other.is_a?(Agent) && actor.eql?(other.actor) end |
#id ⇒ String
Get the wrapped actor’s ID.
If the actor implements ‘#agent_id`, we will call it and return that value. Otherwise, we call `#id`. If the the actor does not implement either of these methods, we raise a NoIdentifierError.
65 66 67 68 69 70 71 72 73 |
# File 'lib/checkpoint/agent.rb', line 65 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 |
#to_agent ⇒ Object
Convert this object to an Agent.
For Checkpoint-supplied Agents, this is an identity operation, but it allows consistent handling of the built-in types and application-supplied types that will either implement this interface or convert themselves to a built-in type. This removes the requirement to extend Checkpoint types or bind to a specific conversion method.
40 41 42 |
# File 'lib/checkpoint/agent.rb', line 40 def to_agent self end |
#token ⇒ Object
75 76 77 |
# File 'lib/checkpoint/agent.rb', line 75 def token @token ||= Token.new(type, id) end |
#type ⇒ String
Get the wrapped actor’s type.
If the actor implements ‘#agent_type`, we will return that. Otherwise, we use the actors’s class name.
50 51 52 53 54 55 56 |
# File 'lib/checkpoint/agent.rb', line 50 def type if actor.respond_to?(:agent_type) actor.agent_type else actor.class end.to_s end |