Class: Cogitate::Models::Agent
- Inherits:
-
Object
- Object
- Cogitate::Models::Agent
- Extended by:
- Forwardable
- Includes:
- Contracts
- Defined in:
- lib/cogitate/models/agent.rb,
lib/cogitate/models/agent/serializer.rb,
lib/cogitate/models/agent/with_token.rb
Overview
Consider adding #to_token so that an Agent can fulfill the AgentWithToken interface
An Agent is a “bucket” of attributes. It represents a single acting entity:
-
a Person - the human clacking away at the keyboard requesting things
-
a Service - an application that “does stuff” to data
Defined Under Namespace
Classes: Serializer, WithToken
Instance Attribute Summary collapse
-
#primary_identifier ⇒ Cogitate::Interfaces::IdentifierInterface
readonly
What has been assigned as the primary identifier of this agent.
Class Method Summary collapse
- .build_with_encoded_id(encoded_identifier:) ⇒ Object
- .build_with_identifying_information(strategy:, identifying_value:, **keywords, &block) ⇒ Object
Instance Method Summary collapse
-
#add_email(input) ⇒ Object
private
I am not yet set on this method being part of the public API.
-
#add_identifier(identifier) ⇒ Cogitate::Interfaces::IdentifierInterface
Add an identifier to the agent.
-
#add_verified_identifier(identifier) ⇒ Cogitate::Interfaces::IdentifierInterface
Add a verified identifier to the agent.
-
#ids ⇒ Array
Consider the scenario in which a student assigns a faculty member (via an email address) as a collaborating researcher.
-
#initialize(identifier:, container: default_container, serializer_builder: default_serializer_builder) {|_self| ... } ⇒ Agent
constructor
A new instance of Agent.
-
#with_emails ⇒ Enumerator?
Nil if a block is given else an Enumerator.
-
#with_identifiers ⇒ Enumerator?
Nil if a block is given else an Enumerator.
-
#with_verified_identifiers ⇒ Enumerator?
Nil if a block is given else an Enumerator.
Constructor Details
#initialize(identifier:, container: default_container, serializer_builder: default_serializer_builder) {|_self| ... } ⇒ Agent
I’m choosing the :identifier as the input and :primary_identifier as the attribute. I believe it is possible that during the process that builds the Agent, I may encounter a more applicable primary_identifier.
Returns a new instance of Agent.
36 37 38 39 40 41 42 43 44 |
# File 'lib/cogitate/models/agent.rb', line 36 def initialize(identifier:, container: default_container, serializer_builder: default_serializer_builder) self.identifiers = container.new self.verified_identifiers = container.new self.primary_identifier = identifier self.serializer = serializer_builder.call(agent: self) self.emails = container.new yield(self) if block_given? self end |
Instance Attribute Details
#primary_identifier ⇒ Cogitate::Interfaces::IdentifierInterface
Returns What has been assigned as the primary identifier of this agent.
101 102 103 |
# File 'lib/cogitate/models/agent.rb', line 101 def primary_identifier @primary_identifier end |
Class Method Details
.build_with_encoded_id(encoded_identifier:) ⇒ Object
24 25 26 27 |
# File 'lib/cogitate/models/agent.rb', line 24 def self.build_with_encoded_id(encoded_identifier:) strategy, = Cogitate::Client.(encoded_identifier) (strategy: strategy, identifying_value: ) end |
.build_with_identifying_information(strategy:, identifying_value:, **keywords, &block) ⇒ Object
18 19 20 21 |
# File 'lib/cogitate/models/agent.rb', line 18 def self.(strategy:, identifying_value:, **keywords, &block) identifier = Cogitate::Models::Identifier.new(strategy: strategy, identifying_value: ) new(identifier: identifier, **keywords, &block) end |
Instance Method Details
#add_email(input) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
I am not yet set on this method being part of the public API.
88 89 90 |
# File 'lib/cogitate/models/agent.rb', line 88 def add_email(input) emails << input end |
#add_identifier(identifier) ⇒ Cogitate::Interfaces::IdentifierInterface
Add an identifier to the agent.
53 54 55 56 |
# File 'lib/cogitate/models/agent.rb', line 53 def add_identifier(identifier) identifiers << identifier identifier end |
#add_verified_identifier(identifier) ⇒ Cogitate::Interfaces::IdentifierInterface
Add a verified identifier to the agent.
73 74 75 76 |
# File 'lib/cogitate/models/agent.rb', line 73 def add_verified_identifier(identifier) verified_identifiers << identifier identifier end |
#ids ⇒ Array
Consider the scenario in which a student assigns a faculty member (via an email address) as a collaborating researcher. That faculty member should have permission to collaborate on the student’s work. The permissions are stored as the Faculty’s email. Then the Faculty authenticates with a NetID (a canonical identifier for the institution that stood up this Cogitate instance) and associates the NetID with their email address.
At that point we want to allow objects associated with both the NetID and connected email to be available to the faculty.
117 118 119 |
# File 'lib/cogitate/models/agent.rb', line 117 def ids [id] + with_verified_identifiers.map(&:id) end |
#with_emails ⇒ Enumerator?
Returns nil if a block is given else an Enumerator.
94 95 96 97 98 |
# File 'lib/cogitate/models/agent.rb', line 94 def with_emails return enum_for(:with_emails) unless block_given? emails.each { |email| yield(email) } nil end |
#with_identifiers ⇒ Enumerator?
Returns nil if a block is given else an Enumerator.
60 61 62 63 64 |
# File 'lib/cogitate/models/agent.rb', line 60 def with_identifiers return enum_for(:with_identifiers) unless block_given? identifiers.each { |identifier| yield(identifier) } nil end |
#with_verified_identifiers ⇒ Enumerator?
Returns nil if a block is given else an Enumerator.
80 81 82 83 84 |
# File 'lib/cogitate/models/agent.rb', line 80 def with_verified_identifiers return enum_for(:with_verified_identifiers) unless block_given? verified_identifiers.each { |identifier| yield(identifier) } nil end |