Class: RubyCqrs::Data::InMemoryEventStore
- Inherits:
-
Object
- Object
- RubyCqrs::Data::InMemoryEventStore
- Includes:
- EventStore
- Defined in:
- lib/ruby_cqrs/data/in_memory_event_store.rb
Instance Method Summary collapse
-
#initialize ⇒ InMemoryEventStore
constructor
A new instance of InMemoryEventStore.
- #load_by(guid, command_context) ⇒ Object
- #save(changes, command_context) ⇒ Object
Constructor Details
#initialize ⇒ InMemoryEventStore
Returns a new instance of InMemoryEventStore.
6 7 8 9 10 |
# File 'lib/ruby_cqrs/data/in_memory_event_store.rb', line 6 def initialize @aggregate_store = {} @event_store = {} @snapshot_store = {} end |
Instance Method Details
#load_by(guid, command_context) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ruby_cqrs/data/in_memory_event_store.rb', line 12 def load_by guid, command_context key = guid.to_sym state = { :aggregate_id => guid, :aggregate_type => @aggregate_store[key][:type] } if @snapshot_store.has_key? key extract_snapshot_into key, state else state[:events] = @event_store[key][:events] end state end |
#save(changes, command_context) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby_cqrs/data/in_memory_event_store.rb', line 26 def save changes, command_context changes.each do |change| key = change[:aggregate_id].to_sym verify_state key, change end changes.each do |change| key = change[:aggregate_id].to_sym create_state key, change update_state key, change end nil end |