Class: Legion::Settings::Extensions::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/settings/extensions/store.rb

Overview

Thread-safe registry store backed by Concurrent::Map.

Each store holds one type of entry (extensions, runners, or tools). Entries are plain hashes keyed by normalized string name. Read operations return frozen duplicates so callers cannot mutate internals.

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.



14
15
16
# File 'lib/legion/settings/extensions/store.rb', line 14

def initialize
  @map = Concurrent::Map.new
end

Instance Method Details

#allObject



29
30
31
32
33
# File 'lib/legion/settings/extensions/store.rb', line 29

def all
  snapshot = @map.values.map(&:dup)
  snapshot.each(&:freeze)
  snapshot.freeze
end

#any?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/legion/settings/extensions/store.rb', line 64

def any?
  @map.size.positive?
end

#clearObject



68
69
70
# File 'lib/legion/settings/extensions/store.rb', line 68

def clear
  @map.clear
end

#delete(name) ⇒ Object



42
43
44
# File 'lib/legion/settings/extensions/store.rb', line 42

def delete(name)
  @map.delete(normalize_key(name))
end

#delete_where(&block) ⇒ Object



46
47
48
# File 'lib/legion/settings/extensions/store.rb', line 46

def delete_where(&block)
  @map.each_pair { |k, v| @map.delete(k) if block.call(v) }
end

#filter(**_criteria, &block) ⇒ Object



35
36
37
38
39
40
# File 'lib/legion/settings/extensions/store.rb', line 35

def filter(**_criteria, &block)
  result = @map.values.map(&:dup)
  result.select!(&block) if block
  result.each(&:freeze)
  result.freeze
end

#find(name) ⇒ Object



25
26
27
# File 'lib/legion/settings/extensions/store.rb', line 25

def find(name)
  @map[normalize_key(name)]&.dup&.freeze
end

#register(name, metadata = {}) ⇒ Object



18
19
20
21
22
23
# File 'lib/legion/settings/extensions/store.rb', line 18

def register(name,  = {})
  key = normalize_key(name)
  entry = .merge(name: key, registered_at: Time.now)
  @map[key] = entry
  entry.freeze
end

#sizeObject



60
61
62
# File 'lib/legion/settings/extensions/store.rb', line 60

def size
  @map.size
end

#update(name, **extra) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/legion/settings/extensions/store.rb', line 50

def update(name, **extra)
  key = normalize_key(name)
  old_entry = @map[key]
  return nil unless old_entry

  updated = old_entry.dup.merge(extra.merge(updated_at: Time.now))
  @map[key] = updated
  updated.freeze
end