Module: EventSourcery::AggregateRoot::ClassMethods

Defined in:
lib/event_sourcery/aggregate_root.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#event_handlersObject (readonly)

Collection of event handlers for the events that this aggregate cares about

Returns:

  • Hash



66
67
68
# File 'lib/event_sourcery/aggregate_root.rb', line 66

def event_handlers
  @event_handlers
end

Instance Method Details

#apply(*event_classes, &block) ⇒ Object

Register an event handler for the specified event(s)

Examples:

apply TodoAdded do |event|
  @added = true
end

Parameters:

  • event_classes

    one or more event types for which the handler is for

  • block

    the event handler



77
78
79
80
81
# File 'lib/event_sourcery/aggregate_root.rb', line 77

def apply(*event_classes, &block)
  event_classes.each do |event_class|
    @event_handlers[event_class.type] << block
  end
end