Class: Phronomy::Persistence::InMemory
- Inherits:
-
Persistence
- Object
- Persistence
- Phronomy::Persistence::InMemory
- Defined in:
- lib/phronomy/persistence/in_memory.rb
Defined Under Namespace
Classes: Agents, Contents, Executions, Journals
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #capabilities ⇒ Object
-
#initialize ⇒ InMemory
constructor
A new instance of InMemory.
- #synchronize(&block) ⇒ Object
- #transaction ⇒ Object
Constructor Details
#initialize ⇒ InMemory
Returns a new instance of InMemory.
214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/phronomy/persistence/in_memory.rb', line 214 def initialize @monitor = Monitor.new @state = {contents: {}, agents: {}, journals: {}, executions: {}} @contents = Contents.new(self) @agents = Agents.new(self) @journals = Journals.new(self) @executions = Executions.new(self) @activations = Phronomy::Agent::ActivationRegistry.new super(contents: @contents, agents: @agents, journals: @journals, executions: @executions, activations: @activations) end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
212 213 214 |
# File 'lib/phronomy/persistence/in_memory.rb', line 212 def state @state end |
Instance Method Details
#capabilities ⇒ Object
226 227 228 |
# File 'lib/phronomy/persistence/in_memory.rb', line 226 def capabilities {atomic_all: true, atomic_admission: true, optimistic_revision: true}.freeze end |
#synchronize(&block) ⇒ Object
242 243 244 |
# File 'lib/phronomy/persistence/in_memory.rb', line 242 def synchronize(&block) @monitor.synchronize(&block) end |
#transaction ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/phronomy/persistence/in_memory.rb', line 230 def transaction synchronize do snapshot = Marshal.load(Marshal.dump(@state)) begin yield self rescue @state = snapshot raise end end end |