Class: Akasha::Storage::HttpEventStore::Stream
- Inherits:
-
Object
- Object
- Akasha::Storage::HttpEventStore::Stream
- Defined in:
- lib/akasha/storage/http_event_store/stream.rb
Overview
HTTP Eventstore stream.
Instance Method Summary collapse
-
#initialize(client, stream_name) ⇒ Stream
constructor
A new instance of Stream.
-
#read_events(start, page_size) ⇒ Object
Reads events from the stream starting from ‘start` inclusive.
-
#write_events(events) ⇒ Object
Appends events to the stream.
Constructor Details
#initialize(client, stream_name) ⇒ Stream
Returns a new instance of Stream.
6 7 8 9 |
# File 'lib/akasha/storage/http_event_store/stream.rb', line 6 def initialize(client, stream_name) @client = client @stream_name = stream_name end |
Instance Method Details
#read_events(start, page_size) ⇒ Object
Reads events from the stream starting from ‘start` inclusive. If block given, reads all events from the position in pages of `page_size`. If block not given, reads `size` events from the position.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/akasha/storage/http_event_store/stream.rb', line 26 def read_events(start, page_size) if block_given? position = start loop do events = read_events(position, page_size) return if events.empty? yield(events) position += events.size end else safe_read_events(start, page_size) end end |
#write_events(events) ⇒ Object
Appends events to the stream.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/akasha/storage/http_event_store/stream.rb', line 12 def write_events(events) event_hashes = events.map do |event| { event_type: event.name, data: event.data, metadata: event. } end @client.append_to_stream(@stream_name, event_hashes) end |