Class: HistoryBook::Stream
- Inherits:
-
Object
- Object
- HistoryBook::Stream
- Defined in:
- lib/history_book/stream.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#uncommitted_events ⇒ Object
readonly
Returns the value of attribute uncommitted_events.
Instance Method Summary collapse
- #<<(event) ⇒ Object
- #commit ⇒ Object
-
#initialize(id, store) ⇒ Stream
constructor
A new instance of Stream.
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
#events ⇒ Object (readonly)
Returns the value of attribute events.
3 4 5 |
# File 'lib/history_book/stream.rb', line 3 def events @events end |
#uncommitted_events ⇒ Object (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 |
#commit ⇒ Object
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 |