Class: EventStore::Aggregate

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/event_store/aggregate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, type = EventStore.table_name, checkpoint_event = nil) ⇒ Aggregate

Returns a new instance of Aggregate.

[View source]

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

#checkpoint_eventObject (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

#event_streamObject (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

#event_tableObject (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

#idObject (readonly)

Returns the value of attribute id.


7
8
9
# File 'lib/event_store/aggregate.rb', line 7

def id
  @id
end

#snapshotObject (readonly)

Returns the value of attribute snapshot.


7
8
9
# File 'lib/event_store/aggregate.rb', line 7

def snapshot
  @snapshot
end

#typeObject (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

.countObject

[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

.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

#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

#snapshot_exists?Boolean

Returns:

  • (Boolean)
[View source]

26
27
28
# File 'lib/event_store/aggregate.rb', line 26

def snapshot_exists?
  @snapshot.exists?
end