Module: Legion::Gaia::BondTracker

Extended by:
Logging::Helper
Defined in:
lib/legion/gaia/bond_tracker.rb

Overview

TrackerPattern persistence wrapper for the bond stores in BondRegistry. Implements dirty/clean, to_apollo_entries, and from_apollo for integration with TrackerPersistence's flush and hydration cycles.

Class Method Summary collapse

Class Method Details

.dirty!Object



23
24
25
# File 'lib/legion/gaia/bond_tracker.rb', line 23

def dirty!
  @dirty = true
end

.dirty?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/legion/gaia/bond_tracker.rb', line 15

def dirty?
  @dirty ||= false
end

.from_apollo(store:) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/legion/gaia/bond_tracker.rb', line 42

def from_apollo(store:)
  result = store.query(text: 'bond_evidence', tags: %w[bond gaia])
  return unless result.is_a?(Hash) && result[:success] && result[:results]&.any?

  result[:results].each do |entry|
    BondRegistry.hydrate_store(entry) if BondRegistry.respond_to?(:hydrate_store)
  end
rescue StandardError => e
  handle_exception(e, level: :warn, operation: 'gaia.bond_tracker.from_apollo')
end

.mark_clean!Object



19
20
21
# File 'lib/legion/gaia/bond_tracker.rb', line 19

def mark_clean!
  @dirty = false
end

.to_apollo_entriesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/legion/gaia/bond_tracker.rb', line 27

def to_apollo_entries
  return [] unless BondRegistry.respond_to?(:stores)

  entries = []
  BondRegistry.stores.each_value do |store|
    next unless store.respond_to?(:dirty?) && store.dirty?

    store_entries = store.to_apollo_entries
    entries.concat(store_entries)
    store.mark_clean!
  end
  @dirty = false
  entries
end