Skip to content

Commit 6dee2d2

Browse files
committed
Allow to change event type resolver in include AR module
* harmonizes with #837
1 parent 1193273 commit 6dee2d2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

aggregate_root/lib/aggregate_root.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module OnDSL
1414

1515
def on(*event_klasses, &block)
1616
event_klasses.each do |event_klass|
17-
name = event_klass.to_s
17+
name = event_type_for(event_klass)
1818
raise(ArgumentError, "Anonymous class is missing name") if name.start_with? ANONYMOUS_CLASS
1919

2020
handler_name = "on_#{name}"
@@ -80,11 +80,14 @@ def self.with_strategy(strategy)
8080
with(strategy: strategy)
8181
end
8282

83-
def self.with(strategy: ->{ DefaultApplyStrategy.new })
83+
def self.with(strategy: ->{ DefaultApplyStrategy.new }, event_type_resolver: ->(value) { value.to_s })
8484
Module.new do
85-
def self.included(host_class)
85+
define_singleton_method :included do |host_class|
8686
host_class.extend Constructor
8787
host_class.include AggregateMethods
88+
host_class.define_singleton_method :event_type_for do |value|
89+
event_type_resolver.call(value)
90+
end
8891
end
8992

9093
define_method :apply_strategy do

0 commit comments

Comments
 (0)