Module: EventSourcing::Aggregate

Defined in:
lib/event_sourcing/aggregate.rb,
lib/event_sourcing/aggregate/actor.rb,
lib/event_sourcing/aggregate/manager.rb,
lib/event_sourcing/aggregate/message.rb,
lib/event_sourcing/aggregate/wrapper.rb,
lib/event_sourcing/aggregate/manager/cache.rb,
lib/event_sourcing/aggregate/manager/reference.rb,
lib/event_sourcing/aggregate/manager/instance_of.rb

Defined Under Namespace

Modules: ClassMethods Classes: Actor, Manager, Wrapper

Constant Summary collapse

Message =
Value.new(:aggregate, :id, :message)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
# File 'lib/event_sourcing/aggregate.rb', line 5

def self.included(base)
  base.const_set("Actor", EventSourcing::Aggregate::Actor.for(base))
  base.extend ClassMethods
end

Instance Method Details

#_apply(e) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/event_sourcing/aggregate.rb', line 16

def _apply(e)
  if respond_to?("apply_#{e}")
    send("apply_#{e}", e)
  else
    raise "unsupported event #{e}"
  end
end

#initialize(events = []) ⇒ Object



10
11
12
13
14
# File 'lib/event_sourcing/aggregate.rb', line 10

def initialize(events = [])
  events.each do |e|
    _apply(e)
  end
end