Class: Rbdux::Stores::MemoryStore
- Inherits:
-
Object
- Object
- Rbdux::Stores::MemoryStore
- Defined in:
- lib/rbdux/stores/memory_store.rb
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
- #fetch(key, default_value = nil) ⇒ Object
- #replace(state) ⇒ Object
- #set(key, value) ⇒ Object
Class Method Details
.with_state(state) ⇒ Object
6 7 8 |
# File 'lib/rbdux/stores/memory_store.rb', line 6 def self.with_state(state) MemoryStore.new(state) end |
Instance Method Details
#all ⇒ Object
18 19 20 |
# File 'lib/rbdux/stores/memory_store.rb', line 18 def all state end |
#fetch(key, default_value = nil) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/rbdux/stores/memory_store.rb', line 10 def fetch(key, default_value = nil) if block_given? state.fetch(key) { yield } else state.fetch(key, default_value) end end |
#replace(state) ⇒ Object
28 29 30 31 32 |
# File 'lib/rbdux/stores/memory_store.rb', line 28 def replace(state) @lock.synchronize do @state = state end end |
#set(key, value) ⇒ Object
22 23 24 25 26 |
# File 'lib/rbdux/stores/memory_store.rb', line 22 def set(key, value) @lock.synchronize do state[key] = value end end |