Class: EventStoreClient::InMemory
- Inherits:
-
Object
- Object
- EventStoreClient::InMemory
- Defined in:
- lib/event_store_client/adapters/in_memory.rb
Defined Under Namespace
Classes: Response
Instance Attribute Summary collapse
-
#event_store ⇒ Object
readonly
Returns the value of attribute event_store.
Instance Method Summary collapse
-
#append_to_stream(stream_name, events, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument,Metrics/LineLength.
-
#delete_stream(stream_name, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
- #link_to(stream_name, events) ⇒ Object
- #listen(subscription, options: {}) ⇒ Object
- #read(stream_name, options: {}) ⇒ Object
- #read_all_from_stream(stream_name, options: {}) ⇒ Object
- #subscribe_to_stream(subscription) ⇒ Object
-
#tombstone_stream(stream_name, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
Instance Attribute Details
#event_store ⇒ Object (readonly)
Returns the value of attribute event_store.
11 12 13 |
# File 'lib/event_store_client/adapters/in_memory.rb', line 11 def event_store @event_store end |
Instance Method Details
#append_to_stream(stream_name, events, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument,Metrics/LineLength
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/event_store_client/adapters/in_memory.rb', line 13 def append_to_stream(stream_name, events, options: {}) # rubocop:disable Lint/UnusedMethodArgument,Metrics/LineLength event_store[stream_name] = [] unless event_store.key?(stream_name) [events].flatten.each do |event| event_store[stream_name].unshift( 'eventId' => event.id, 'data' => event.data, 'eventType' => event.type, 'metaData' => event., 'positionEventNumber' => event_store[stream_name].length ) end end |
#delete_stream(stream_name, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
26 27 28 |
# File 'lib/event_store_client/adapters/in_memory.rb', line 26 def delete_stream(stream_name, options: {}) # rubocop:disable Lint/UnusedMethodArgument event_store.delete(stream_name) end |
#link_to(stream_name, events) ⇒ Object
60 61 62 |
# File 'lib/event_store_client/adapters/in_memory.rb', line 60 def link_to(stream_name, events, **) append_to_stream(stream_name, events) end |
#listen(subscription, options: {}) ⇒ Object
64 65 66 |
# File 'lib/event_store_client/adapters/in_memory.rb', line 64 def listen(subscription, options: {}) # TODO: implement method body end |
#read(stream_name, options: {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/event_store_client/adapters/in_memory.rb', line 34 def read(stream_name, options: {}) start = [:start] == 'head' ? [:start] : [:start].to_i direction = [:direction] || 'forward' response = if %w[forward forwards].include?(direction) read_stream_forward(stream_name, start: start) else read_stream_backward(stream_name, start: start) end res = Response.new(response.to_json, 200) return [] if res.body.nil? || res.body.empty? JSON.parse(res.body)['entries'].map do |entry| deserialize_event(entry) end.reverse end |
#read_all_from_stream(stream_name, options: {}) ⇒ Object
52 53 54 |
# File 'lib/event_store_client/adapters/in_memory.rb', line 52 def read_all_from_stream(stream_name, options: {}) read(stream_name, options: ) end |
#subscribe_to_stream(subscription) ⇒ Object
56 57 58 |
# File 'lib/event_store_client/adapters/in_memory.rb', line 56 def subscribe_to_stream(subscription, **) # TODO: implement method body end |
#tombstone_stream(stream_name, options: {}) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
30 31 32 |
# File 'lib/event_store_client/adapters/in_memory.rb', line 30 def tombstone_stream(stream_name, options: {}) # rubocop:disable Lint/UnusedMethodArgument event_store.delete(stream_name) end |