Module: AgentManager

Defined in:
backend/app/model/mixins/agent_manager.rb

Defined Under Namespace

Modules: Mixin Classes: AuthorizedNameError

Constant Summary collapse

AGENT_MUST_BE_UNIQUE =
"Agent must be unique".freeze
AGENT_MUST_BE_UNIQUE_MYSQL_CONSTRAINT =
/Duplicate entry .* for key 'sha1_agent_person'/.freeze
AGENT_SUBRECORDS_WITH_SUBJECTS =
[
  'agent_functions', 'agent_occupations', 'agent_places', 'agent_resources', 'agent_topics'
].freeze

Class Method Summary collapse

Class Method Details

.agent_type_of(agent_class) ⇒ Object



38
39
40
# File 'backend/app/model/mixins/agent_manager.rb', line 38

def self.agent_type_of(agent_class)
  @@registered_agents[agent_class]
end

.known_agent_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'backend/app/model/mixins/agent_manager.rb', line 43

def self.known_agent_type?(type)
  registered_agents.any? {|a| a[:jsonmodel].to_s == type}
end

.linked_subjects(id, table, type) ⇒ Object



48
49
50
51
52
53
54
55
# File 'backend/app/model/mixins/agent_manager.rb', line 48

def self.linked_subjects(id, table, type)
  Subject
  .join("#{table}_rlshp", :subject_id => :subject__id)
  .filter("#{table}_rlshp__#{type}_id".to_sym => id)
  .select(:subject__id)
  .distinct
  .all.map {|row| row[:id]}
end

.model_for(type) ⇒ Object



24
25
26
27
28
29
30
# File 'backend/app/model/mixins/agent_manager.rb', line 24

def self.model_for(type)
  self.registered_agents.each do |agent_type|
    return agent_type[:model] if (agent_type[:jsonmodel].to_s == type)
  end

  return nil
end

.register_agent_type(agent_class, opts) ⇒ Object



18
19
20
21
# File 'backend/app/model/mixins/agent_manager.rb', line 18

def self.register_agent_type(agent_class, opts)
  opts[:model] = agent_class
  @@registered_agents[agent_class] = opts
end

.registered_agentsObject



33
34
35
# File 'backend/app/model/mixins/agent_manager.rb', line 33

def self.registered_agents
  @@registered_agents.values
end