Class: Cogitate::Models::Agent

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

TODO:

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier:, container: default_container, serializer_builder: default_serializer_builder) {|_self| ... } ⇒ Agent

Note:

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.

Yields:

  • (_self)

Yield Parameters:



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_identifierCogitate::Interfaces::IdentifierInterface

Returns What has been assigned as the primary identifier of this agent.

Returns:



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, identifying_value = Cogitate::Client.extract_strategy_and_identifying_value(encoded_identifier)
  build_with_identifying_information(strategy: strategy, identifying_value: 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.build_with_identifying_information(strategy:, identifying_value:, **keywords, &block)
  identifier = Cogitate::Models::Identifier.new(strategy: strategy, identifying_value: 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

#idsArray

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.

Returns:

  • (Array)

    of ids for each of the verified identifiers



117
118
119
# File 'lib/cogitate/models/agent.rb', line 117

def ids
  [id] + with_verified_identifiers.map(&:id)
end

#with_emailsEnumerator?

Returns nil if a block is given else an Enumerator.

Returns:

  • (Enumerator, nil)

    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_identifiersEnumerator?

Returns nil if a block is given else an Enumerator.

Returns:

  • (Enumerator, nil)

    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_identifiersEnumerator?

Returns nil if a block is given else an Enumerator.

Returns:

  • (Enumerator, nil)

    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