Module: Legion::Gaia::BondRegistry

Defined in:
lib/legion/gaia/bond_registry.rb

Class Method Summary collapse

Class Method Details

.all_bondsObject



24
25
26
27
# File 'lib/legion/gaia/bond_registry.rb', line 24

def all_bonds
  @bonds ||= {}
  @bonds.values
end

.hydrate_from_apollo(store: nil) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/legion/gaia/bond_registry.rb', line 29

def hydrate_from_apollo(store: nil) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
  return unless store

  result = store.query(text: 'partner', tags: %w[self-knowledge])
  return unless result.is_a?(Hash) && result[:success] && result[:results]&.any?

  result[:results].each do |entry|
    content = entry[:content].to_s
    next unless content.match?(/partner/i)

    identities = extract_identity_keys(content)
    priority = content.match?(/primary/i) ? :primary : :normal

    identities.each { |id| register(id, role: :partner, priority: priority) }
  end
rescue StandardError => e
  Legion::Logging.warn "BondRegistry hydration failed: #{e.message}" if defined?(Legion::Logging)
end

.partner?(identity) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/legion/gaia/bond_registry.rb', line 14

def partner?(identity)
  role(identity) == :partner
end

.register(identity, role:, priority: :normal) ⇒ Object



8
9
10
11
12
# File 'lib/legion/gaia/bond_registry.rb', line 8

def register(identity, role:, priority: :normal)
  @bonds ||= {}
  @bonds[identity.to_s] = { identity: identity.to_s, role: role.to_sym, priority: priority.to_sym,
                            since: Time.now.utc }
end

.reset!Object



48
49
50
# File 'lib/legion/gaia/bond_registry.rb', line 48

def reset!
  @bonds = {}
end

.role(identity) ⇒ Object



18
19
20
21
22
# File 'lib/legion/gaia/bond_registry.rb', line 18

def role(identity)
  @bonds ||= {}
  entry = @bonds[identity.to_s]
  entry ? entry[:role] : :unknown
end