Class: Aggregates::InMemoryStorageBackend

Inherits:
StorageBackend show all
Defined in:
lib/aggregates/in_memory_storage_backend.rb

Overview

This is an extremely simple storage backend that retains all events and commands in process memory. This method does not persist beyond application restarts and should generally only be used in testing.

Instance Method Summary collapse

Constructor Details

#initializeInMemoryStorageBackend

Returns a new instance of InMemoryStorageBackend.



8
9
10
11
12
13
# File 'lib/aggregates/in_memory_storage_backend.rb', line 8

def initialize
  super()

  @events = {}
  @commands = {}
end

Instance Method Details

#load_commands_by_aggregate_id(aggregate_id) ⇒ Object



27
28
29
# File 'lib/aggregates/in_memory_storage_backend.rb', line 27

def load_commands_by_aggregate_id(aggregate_id)
  @commands[aggregate_id] ||= []
end

#load_events_by_aggregate_id(aggregate_id) ⇒ Object



23
24
25
# File 'lib/aggregates/in_memory_storage_backend.rb', line 23

def load_events_by_aggregate_id(aggregate_id)
  @events[aggregate_id] ||= []
end

#store_command(command) ⇒ Object



15
16
17
# File 'lib/aggregates/in_memory_storage_backend.rb', line 15

def store_command(command)
  load_commands_by_aggregate_id(command.aggregate_id) << command
end

#store_event(event) ⇒ Object



19
20
21
# File 'lib/aggregates/in_memory_storage_backend.rb', line 19

def store_event(event)
  load_events_by_aggregate_id(event.aggregate_id) << event
end