Class: Quonfig::ConfigStore
- Inherits:
-
Object
- Object
- Quonfig::ConfigStore
- Defined in:
- lib/quonfig/config_store.rb
Overview
In-memory store of configs keyed by config key.
Mirrors sdk-node’s ConfigStore (src/store.ts). Integration tests and the new Resolver/Evaluator trio construct this directly, independent of any Client/ConfigLoader plumbing.
Instance Method Summary collapse
- #all_configs ⇒ Object
- #clear ⇒ Object
- #get(key) ⇒ Object
-
#initialize(initial_configs = nil) ⇒ ConfigStore
constructor
A new instance of ConfigStore.
- #keys ⇒ Object
- #set(key, config) ⇒ Object
Constructor Details
#initialize(initial_configs = nil) ⇒ ConfigStore
Returns a new instance of ConfigStore.
10 11 12 13 14 15 16 |
# File 'lib/quonfig/config_store.rb', line 10 def initialize(initial_configs = nil) @lock = Concurrent::ReadWriteLock.new @configs = Concurrent::Map.new return unless initial_configs initial_configs.each { |k, v| @configs[k] = v } end |
Instance Method Details
#all_configs ⇒ Object
36 37 38 39 40 |
# File 'lib/quonfig/config_store.rb', line 36 def all_configs h = {} @configs.each_pair { |k, v| h[k] = v } h end |
#clear ⇒ Object
26 27 28 29 30 |
# File 'lib/quonfig/config_store.rb', line 26 def clear @lock.with_write_lock do @configs.keys.each { |k| @configs.delete(k) } end end |
#get(key) ⇒ Object
18 19 20 |
# File 'lib/quonfig/config_store.rb', line 18 def get(key) @configs[key] end |
#keys ⇒ Object
32 33 34 |
# File 'lib/quonfig/config_store.rb', line 32 def keys @configs.keys end |
#set(key, config) ⇒ Object
22 23 24 |
# File 'lib/quonfig/config_store.rb', line 22 def set(key, config) @lock.with_write_lock { @configs[key] = config } end |