class Checkpoint::Agent
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 {Agent::Resolver} registered with an {Checkpoint::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.
Attributes
Public Class Methods
Create an Agent
, wrapping a concrete actor.
When retrieving the ID or type, we will delegate to the the actor at that time. See the {#id} and {#type} methods for exact semantics.
# File lib/checkpoint/agent.rb, line 29 def initialize(actor) @actor = actor end
Public Instance Methods
Check whether two Agents refer to the same concrete actor by type and id. @param other [Agent] Another Agent
to compare with @return [Boolean] true when the other Agent's type and id are equal.
# File lib/checkpoint/agent.rb, line 90 def ==(other) other.is_a?(Agent) && type == other.type && id == other.id end
Check whether two Agents refer to the same concrete actor. @param other [Agent] Another Agent
to compare with @return [Boolean] true when the other Agent's actor is the same as
determined by comparing them with `#eql?`.
# File lib/checkpoint/agent.rb, line 83 def eql?(other) other.is_a?(Agent) && actor.eql?(other.actor) end
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}.
@return [String] the actor's ID after calling `#to_s` on it.
# 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
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.
# File lib/checkpoint/agent.rb, line 40 def to_agent self end
# File lib/checkpoint/agent.rb, line 75 def token @token ||= Token.new(type, id) end
Get the wrapped actor's type.
If the actor implements `#agent_type`, we will return that. Otherwise, we use the actors's class name.
@return [String] the name of the actor's type after calling `#to_s` on it.
# 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