Class: Akasha::Storage::MemoryEventStore::Stream

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

Overview

Memory-based event stream.

Instance Method Summary collapse

Constructor Details

#initializeStream

Returns a new instance of Stream.



6
7
8
# File 'lib/akasha/storage/memory_event_store/stream.rb', line 6

def initialize
  @events = []
end

Instance Method Details

#read_events(position, size, &block) ⇒ Object

Reads events from the stream starting from ‘position` inclusive. If block given, reads all events from the position in chunks of `size`. If block not given, reads `size` events from the position.



19
20
21
22
23
24
25
# File 'lib/akasha/storage/memory_event_store/stream.rb', line 19

def read_events(position, size, &block)
  if block_given?
    @events.lazy.drop(position).each_slice(size, &block)
  else
    @events[position..position + size]
  end
end

#write_events(events) ⇒ Object

Appends events to the stream.



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

def write_events(events)
  @events += events
end