Class: LaunchDarkly::InMemoryFeatureStore
- Inherits:
-
Object
- Object
- LaunchDarkly::InMemoryFeatureStore
- Defined in:
- lib/ldclient-rb/feature_store.rb
Instance Method Summary collapse
- #all ⇒ Object
- #delete(key, version) ⇒ Object
- #get(key) ⇒ Object
- #init(fs) ⇒ Object
-
#initialize ⇒ InMemoryFeatureStore
constructor
A new instance of InMemoryFeatureStore.
- #initialized? ⇒ Boolean
- #stop ⇒ Object
- #upsert(key, feature) ⇒ Object
Constructor Details
#initialize ⇒ InMemoryFeatureStore
Returns a new instance of InMemoryFeatureStore.
5 6 7 8 9 |
# File 'lib/ldclient-rb/feature_store.rb', line 5 def initialize @features = Hash.new @lock = Concurrent::ReadWriteLock.new @initialized = Concurrent::AtomicBoolean.new(false) end |
Instance Method Details
#all ⇒ Object
18 19 20 21 22 |
# File 'lib/ldclient-rb/feature_store.rb', line 18 def all @lock.with_read_lock do @features.select { |_k, f| not f[:deleted] } end end |
#delete(key, version) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ldclient-rb/feature_store.rb', line 24 def delete(key, version) @lock.with_write_lock do old = @features[key.to_sym] if !old.nil? && old[:version] < version old[:deleted] = true old[:version] = version @features[key.to_sym] = old elsif old.nil? @features[key.to_sym] = { deleted: true, version: version } end end end |
#get(key) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/ldclient-rb/feature_store.rb', line 11 def get(key) @lock.with_read_lock do f = @features[key.to_sym] (f.nil? || f[:deleted]) ? nil : f end end |
#init(fs) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/ldclient-rb/feature_store.rb', line 38 def init(fs) @lock.with_write_lock do @features.replace(fs) @initialized.make_true end end |
#initialized? ⇒ Boolean
55 56 57 |
# File 'lib/ldclient-rb/feature_store.rb', line 55 def initialized? @initialized.value end |
#stop ⇒ Object
59 60 61 |
# File 'lib/ldclient-rb/feature_store.rb', line 59 def stop # nothing to do end |
#upsert(key, feature) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/ldclient-rb/feature_store.rb', line 45 def upsert(key, feature) @lock.with_write_lock do old = @features[key.to_sym] if old.nil? || old[:version] < feature[:version] @features[key.to_sym] = feature end end end |