Class: Akasha::Storage::MemoryEventStore

Inherits:
Object
  • Object
show all
Defined in:
lib/akasha/storage/memory_event_store.rb,
lib/akasha/storage/memory_event_store/stream.rb

Overview

Memory-based event store.

Defined Under Namespace

Classes: Stream

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMemoryEventStore

Returns a new instance of MemoryEventStore


12
13
14
15
16
17
18
19
20
21
# File 'lib/akasha/storage/memory_event_store.rb', line 12

def initialize
  store = self
  @streams = Hash.new do |streams, name|
    streams[name] = Stream.new do |new_events|
      store.update_projections(new_events)
      new_events
    end
  end
  @projections = []
end

Instance Attribute Details

#streamsObject (readonly)

Access to streams Example:

store.streams['some-stream-name']

10
11
12
# File 'lib/akasha/storage/memory_event_store.rb', line 10

def streams
  @streams
end

Instance Method Details

#merge_all_by_event(into:, only:, namespace: nil) ⇒ Object

Merges all streams into one, filtering the resulting stream so it only contains events with the specified names.

Arguments:

`new_stream_name` - name of the new stream
`only` - array of event names
`namespace` - optional namespace; if provided, the resulting stream will
              only contain events with the same metadata.namespace

31
32
33
34
35
36
37
38
39
40
41
# File 'lib/akasha/storage/memory_event_store.rb', line 31

def merge_all_by_event(into:, only:, namespace: nil)
  new_stream = Stream.new do |new_events|
    new_events.select do |event|
      (namespace.nil? || namespace == event.[:namespace]) &&
        only.include?(event.name)
    end
  end
  @streams[into] = new_stream
  @projections << new_stream
  new_stream
end