Class: EventStore::Aggregate
- Inherits:
-
Object
- Object
- EventStore::Aggregate
- Extended by:
- Forwardable
- Defined in:
- lib/event_store/aggregate.rb
Instance Attribute Summary collapse
-
#checkpoint_event ⇒ Object
readonly
Returns the value of attribute checkpoint_event.
-
#event_stream ⇒ Object
readonly
Returns the value of attribute event_stream.
-
#event_table ⇒ Object
readonly
Returns the value of attribute event_table.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#snapshot ⇒ Object
readonly
Returns the value of attribute snapshot.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #append(events, logger) ⇒ Object
-
#initialize(id, type = EventStore.table_name, checkpoint_event = nil) ⇒ Aggregate
constructor
A new instance of Aggregate.
- #snapshot_exists? ⇒ Boolean
Constructor Details
permalink #initialize(id, type = EventStore.table_name, checkpoint_event = nil) ⇒ Aggregate
Returns a new instance of Aggregate.
38 39 40 41 42 43 44 45 |
# File 'lib/event_store/aggregate.rb', line 38 def initialize(id, type = EventStore.table_name, checkpoint_event = nil) @id = id @type = type @checkpoint_event = checkpoint_event @snapshot = Snapshot.new(self) @event_stream = EventStream.new(self) end |
Instance Attribute Details
permalink #checkpoint_event ⇒ Object (readonly)
Returns the value of attribute checkpoint_event.
7 8 9 |
# File 'lib/event_store/aggregate.rb', line 7 def checkpoint_event @checkpoint_event end |
permalink #event_stream ⇒ Object (readonly)
Returns the value of attribute event_stream.
7 8 9 |
# File 'lib/event_store/aggregate.rb', line 7 def event_stream @event_stream end |
permalink #event_table ⇒ Object (readonly)
Returns the value of attribute event_table.
7 8 9 |
# File 'lib/event_store/aggregate.rb', line 7 def event_table @event_table end |
permalink #id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/event_store/aggregate.rb', line 7 def id @id end |
permalink #snapshot ⇒ Object (readonly)
Returns the value of attribute snapshot.
7 8 9 |
# File 'lib/event_store/aggregate.rb', line 7 def snapshot @snapshot end |
permalink #type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/event_store/aggregate.rb', line 7 def type @type end |
Class Method Details
permalink .count ⇒ Object
[View source]
30 31 32 |
# File 'lib/event_store/aggregate.rb', line 30 def self.count EventStore.db.from(EventStore.fully_qualified_table).select(:aggregate_id).distinct.count end |
permalink .ids(offset, limit) ⇒ Object
[View source]
34 35 36 |
# File 'lib/event_store/aggregate.rb', line 34 def self.ids(offset, limit) EventStore.db.from(EventStore.fully_qualified_table).select(:aggregate_id).distinct.order(:aggregate_id).limit(limit, offset).all.map{|item| item[:aggregate_id]} end |
Instance Method Details
permalink #append(events, logger) ⇒ Object
[View source]
47 48 49 50 51 52 53 |
# File 'lib/event_store/aggregate.rb', line 47 def append(events, logger) logger.debug("EventStore#append, appending to event stream") event_stream.append(events, logger) do |prepared_events| logger.debug("EventStore#append, storing snapshot") snapshot.store_snapshot(prepared_events, logger) end end |
permalink #snapshot_exists? ⇒ Boolean
26 27 28 |
# File 'lib/event_store/aggregate.rb', line 26 def snapshot_exists? @snapshot.exists? end |