Class: LaunchDarkly::InMemoryFeatureStore
- Inherits:
-
Object
- Object
- LaunchDarkly::InMemoryFeatureStore
- Defined in:
- lib/ldclient-rb/stream.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
- #upsert(key, feature) ⇒ Object
Constructor Details
#initialize ⇒ InMemoryFeatureStore
Returns a new instance of InMemoryFeatureStore.
12 13 14 15 16 |
# File 'lib/ldclient-rb/stream.rb', line 12 def initialize() @features = Hash.new @lock = Concurrent::ReadWriteLock.new @initialized = Concurrent::AtomicBoolean.new(false) end |
Instance Method Details
#all ⇒ Object
25 26 27 28 29 |
# File 'lib/ldclient-rb/stream.rb', line 25 def all() @lock.with_read_lock { @features.select {|k,f| not f[:deleted]} } end |
#delete(key, version) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ldclient-rb/stream.rb', line 31 def delete(key, version) @lock.with_write_lock { old = @features[key.to_sym] if old != nil and 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 |
#get(key) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/ldclient-rb/stream.rb', line 18 def get(key) @lock.with_read_lock { f = @features[key.to_sym] (f.nil? || f[:deleted]) ? nil : f } end |
#init(fs) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/ldclient-rb/stream.rb', line 45 def init(fs) @lock.with_write_lock { @features.replace(fs) @initialized.make_true } end |
#initialized? ⇒ Boolean
62 63 64 |
# File 'lib/ldclient-rb/stream.rb', line 62 def initialized?() @initialized.value end |
#upsert(key, feature) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/ldclient-rb/stream.rb', line 52 def upsert(key, feature) @lock.with_write_lock { old = @features[key.to_sym] if old.nil? or old[:version] < feature[:version] @features[key.to_sym] = feature end } end |