Class: Quonfig::ConfigStore

Inherits:
Object
  • Object
show all
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.

Thread-safety: backed by Concurrent::Map, whose per-key reads, writes, and deletes are atomic. There is no compound multi-key operation here that needs an outer lock — envelope application in ConfigLoader is a sequence of independent set/delete calls, and readers tolerate seeing the in-progress mix. Eventual consistency across an envelope is acceptable and matches sdk-node behavior.

Instance Method Summary collapse

Constructor Details

#initialize(initial_configs = nil) ⇒ ConfigStore

Returns a new instance of ConfigStore.



17
18
19
20
21
22
# File 'lib/quonfig/config_store.rb', line 17

def initialize(initial_configs = nil)
  @configs = Concurrent::Map.new
  return unless initial_configs

  initial_configs.each { |k, v| @configs[k] = v }
end

Instance Method Details

#all_configsObject



44
45
46
47
48
# File 'lib/quonfig/config_store.rb', line 44

def all_configs
  h = {}
  @configs.each_pair { |k, v| h[k] = v }
  h
end

#clearObject



36
37
38
# File 'lib/quonfig/config_store.rb', line 36

def clear
  @configs.each_key { |k| @configs.delete(k) }
end

#delete(key) ⇒ Object



32
33
34
# File 'lib/quonfig/config_store.rb', line 32

def delete(key)
  @configs.delete(key)
end

#get(key) ⇒ Object



24
25
26
# File 'lib/quonfig/config_store.rb', line 24

def get(key)
  @configs[key]
end

#keysObject



40
41
42
# File 'lib/quonfig/config_store.rb', line 40

def keys
  @configs.keys
end

#set(key, config) ⇒ Object



28
29
30
# File 'lib/quonfig/config_store.rb', line 28

def set(key, config)
  @configs[key] = config
end