Class: Plutonium::Wizard::Store::Memory
- Defined in:
- lib/plutonium/wizard/store/memory.rb
Overview
In-memory store for fast, DB-free unit tests (and a template for future adapters). Mirrors ActiveRecord's observable behavior.
Instance Method Summary collapse
- #clear(instance_key) ⇒ Object
- #complete(instance_key) ⇒ Object
- #completed?(instance_key:) ⇒ Boolean
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #read(instance_key) ⇒ Object
- #write(instance_key, state, cleanup_after:) ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
9 10 11 |
# File 'lib/plutonium/wizard/store/memory.rb', line 9 def initialize @rows = {} end |
Instance Method Details
#clear(instance_key) ⇒ Object
33 34 35 |
# File 'lib/plutonium/wizard/store/memory.rb', line 33 def clear(instance_key) @rows.delete(instance_key) end |
#complete(instance_key) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/plutonium/wizard/store/memory.rb', line 24 def complete(instance_key) state = @rows.fetch(instance_key) state.status = "completed" state.data = {} state.persisted = {} state.visited = [] state end |
#completed?(instance_key:) ⇒ Boolean
37 38 39 40 |
# File 'lib/plutonium/wizard/store/memory.rb', line 37 def completed?(instance_key:) row = @rows[instance_key] !!row && row.status == "completed" end |
#read(instance_key) ⇒ Object
13 14 15 |
# File 'lib/plutonium/wizard/store/memory.rb', line 13 def read(instance_key) @rows[instance_key]&.dup end |
#write(instance_key, state, cleanup_after:) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/plutonium/wizard/store/memory.rb', line 17 def write(instance_key, state, cleanup_after:) state = state.dup state.instance_key = instance_key state.status ||= "in_progress" @rows[instance_key] = state end |