Class: Rbdux::Stores::ImmutableMemoryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/rbdux/stores/immutable_memory_store.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.with_state(state) ⇒ Object



6
7
8
# File 'lib/rbdux/stores/immutable_memory_store.rb', line 6

def self.with_state(state)
  ImmutableMemoryStore.new(state)
end

Instance Method Details

#allObject



18
19
20
# File 'lib/rbdux/stores/immutable_memory_store.rb', line 18

def all
  state.to_h
end

#fetch(key, default_value = nil) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/rbdux/stores/immutable_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



26
27
28
# File 'lib/rbdux/stores/immutable_memory_store.rb', line 26

def replace(state)
  @state = Hamster::Hash.new(state)
end

#set(key, value) ⇒ Object



22
23
24
# File 'lib/rbdux/stores/immutable_memory_store.rb', line 22

def set(key, value)
  @state = state.put(key, value)
end