Class: EventSorcerer::EventStore
- Inherits:
-
Object
- Object
- EventSorcerer::EventStore
- Defined in:
- lib/event_sorcerer/event_store.rb
Overview
Public: Abstract class for an event store implementation.
Instance Method Summary collapse
-
#append_events(_id, _type, _events, _expected_version) ⇒ Object
Public: Append events to a specified aggregate.
-
#get_current_version(_id, _type) ⇒ Object
Public: Retrieve the current version for a specified aggregate.
-
#get_ids_for_type(_type) ⇒ Object
Public: Retrieve the IDs for a given aggregate class.
-
#read_event_stream(id, type) ⇒ Object
Public: Retrieve the event stream for a specified aggregate.
-
#read_event_streams_for_type(type) ⇒ Object
Public: Retrieve the event stream for all aggregates of a given type.
-
#read_events(_id, _type) ⇒ Object
Public: Retrieve the events for a specified aggregate.
-
#read_multiple_event_streams(ids, type) ⇒ Object
Public: Retrieve the events for multiple aggregates.
-
#with_transaction ⇒ Object
Public: Ensures events appended within the given block are done so atomically.
Instance Method Details
#append_events(_id, _type, _events, _expected_version) ⇒ Object
Public: Append events to a specified aggregate. Should be defined in a
subclass.
_id - UUID of the aggregate as a String. _type - Text representation of aggregate class. _events - Array of JSON-serialized events. _expected_version - The current version of the aggregate.
Raises a NotImplementedError
23 24 25 |
# File 'lib/event_sorcerer/event_store.rb', line 23 def append_events(_id, _type, _events, _expected_version) fail NotImplementedError end |
#get_current_version(_id, _type) ⇒ Object
Public: Retrieve the current version for a specified aggregate. Should
be defined in a subclass.
_id - UUID of the aggregate as a String.
Raises a NotImplementedError
33 34 35 |
# File 'lib/event_sorcerer/event_store.rb', line 33 def get_current_version(_id, _type) fail NotImplementedError end |
#get_ids_for_type(_type) ⇒ Object
Public: Retrieve the IDs for a given aggregate class. Should be defined
in a subclass.
_type - Text representation of aggregate class.
Raises a NotImplementedError
43 44 45 |
# File 'lib/event_sorcerer/event_store.rb', line 43 def get_ids_for_type(_type) fail NotImplementedError end |
#read_event_stream(id, type) ⇒ Object
Public: Retrieve the event stream for a specified aggregate. Should be
defined in a subclass.
id - UUID of the aggregate as a String. type - Text representation of aggregate class.
Returns an EventStream
65 66 67 |
# File 'lib/event_sorcerer/event_store.rb', line 65 def read_event_stream(id, type) EventStream.new id, read_events(id, type), get_current_version(id, type) end |
#read_event_streams_for_type(type) ⇒ Object
Public: Retrieve the event stream for all aggregates of a given type.
Optionally can be defined in subclass to optimize loading these
aggregates with a minimum of external calls.
type - Text representation of aggregate class.
Returns an Array.
76 77 78 |
# File 'lib/event_sorcerer/event_store.rb', line 76 def read_event_streams_for_type(type) read_multiple_event_streams get_ids_for_type(type), type end |
#read_events(_id, _type) ⇒ Object
Public: Retrieve the events for a specified aggregate. Should be defined
in a subclass.
_id - UUID of the aggregate as a String. _type - Text representation of aggregate class.
Raises a NotImplementedError
54 55 56 |
# File 'lib/event_sorcerer/event_store.rb', line 54 def read_events(_id, _type) fail NotImplementedError end |
#read_multiple_event_streams(ids, type) ⇒ Object
Public: Retrieve the events for multiple aggregates. Optionally can be
defined in subclass to optimize loading multiple aggregates with
a minimum of external calls.
ids - Array of UUIDs of the aggregates as Strings. type - Text representation of aggregate class.
Returns an Array.
88 89 90 |
# File 'lib/event_sorcerer/event_store.rb', line 88 def read_multiple_event_streams(ids, type) ids.map { |id| read_event_stream id, type } end |
#with_transaction ⇒ Object
Public: Ensures events appended within the given block are done so
atomically. Should be defined in a subclass.
Raises a NotImplementedError
96 97 98 |
# File 'lib/event_sorcerer/event_store.rb', line 96 def with_transaction fail NotImplementedError end |