Class: SnapshotAggregateRoot::DefaultApplyStrategy

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

Instance Method Summary collapse

Constructor Details

#initialize(strict: true) ⇒ DefaultApplyStrategy

Returns a new instance of DefaultApplyStrategy.



5
6
7
# File 'lib/snapshot_aggregate_root/default_apply_strategy.rb', line 5

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

Instance Method Details

#call(aggregate, event) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/snapshot_aggregate_root/default_apply_strategy.rb', line 9

def call(aggregate, event)
  name = handler_name(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