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.
11 12 13 14 15 |
# File 'lib/ldclient-rb/stream.rb', line 11 def initialize @features = Hash.new @lock = Concurrent::ReadWriteLock.new @initialized = Concurrent::AtomicBoolean.new(false) end |
Instance Method Details
#all ⇒ Object
24 25 26 27 28 |
# File 'lib/ldclient-rb/stream.rb', line 24 def all @lock.with_read_lock do @features.select { |_k, f| not f[:deleted] } end end |
#delete(key, version) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ldclient-rb/stream.rb', line 30 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
17 18 19 20 21 22 |
# File 'lib/ldclient-rb/stream.rb', line 17 def get(key) @lock.with_read_lock do f = @features[key.to_sym] (f.nil? || f[:deleted]) ? nil : f end end |
#init(fs) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/ldclient-rb/stream.rb', line 44 def init(fs) @lock.with_write_lock do @features.replace(fs) @initialized.make_true end end |
#initialized? ⇒ Boolean
61 62 63 |
# File 'lib/ldclient-rb/stream.rb', line 61 def initialized? @initialized.value end |
#upsert(key, feature) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/ldclient-rb/stream.rb', line 51 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 |