Class: AggregateRoot::DefaultApplyStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/aggregate_root/default_apply_strategy.rb

Instance Method Summary collapse

Constructor Details

#initialize(strict: true) ⇒ DefaultApplyStrategy

Returns a new instance of DefaultApplyStrategy.



7
8
9
# File 'lib/aggregate_root/default_apply_strategy.rb', line 7

def initialize(strict: true)
  @strict = strict
end

Instance Method Details

#call(aggregate, event) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/aggregate_root/default_apply_strategy.rb', line 11

def call(aggregate, event)
  name = handler_name(aggregate, event)
  if aggregate.respond_to?(name, true)
    aggregate.method(name).call(event)
  else
    raise MissingHandler.new("Missing handler method #{name} on aggregate #{aggregate.class}") if strict
  end
end