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.



18
19
20
# File 'lib/aggregate_root/default_apply_strategy.rb', line 18

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

Instance Method Details

#call(aggregate, event) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/aggregate_root/default_apply_strategy.rb', line 22

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