Class: HistoryBook::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/history_book/stream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, store) ⇒ Stream

Returns a new instance of Stream.



5
6
7
8
9
10
# File 'lib/history_book/stream.rb', line 5

def initialize(id, store)
  @id = id
  @store = store
  @events = store.load_events(id)
  @uncommitted_events = []
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



3
4
5
# File 'lib/history_book/stream.rb', line 3

def events
  @events
end

#uncommitted_eventsObject (readonly)

Returns the value of attribute uncommitted_events.



3
4
5
# File 'lib/history_book/stream.rb', line 3

def uncommitted_events
  @uncommitted_events
end

Instance Method Details

#<<(event) ⇒ Object



12
13
14
# File 'lib/history_book/stream.rb', line 12

def <<(event)
  @uncommitted_events << event
end

#commitObject



16
17
18
19
20
# File 'lib/history_book/stream.rb', line 16

def commit
  @store.store_events(@id, @uncommitted_events)
  @events.concat(@uncommitted_events)
  @uncommitted_events = []
end