Skip to content

Commit

Permalink
Allow to change event type resolver in include AR module
Browse files Browse the repository at this point in the history
* harmonizes with #837
  • Loading branch information
mostlyobvious committed Jan 5, 2021
1 parent 72752c7 commit dce1e25
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions aggregate_root/lib/aggregate_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module OnDSL

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

handler_name = "on_#{name}"
Expand Down Expand Up @@ -80,11 +80,14 @@ def self.with_strategy(strategy)
with(strategy: strategy)
end

def self.with(strategy: ->{ DefaultApplyStrategy.new })
def self.with(strategy: ->{ DefaultApplyStrategy.new }, event_type_resolver: ->(value) { value.to_s })
Module.new do
def self.included(host_class)
define_singleton_method :included do |host_class|
host_class.extend Constructor
host_class.include AggregateMethods
host_class.define_singleton_method :event_type_for do |value|
event_type_resolver.call(value)
end
end

define_method :apply_strategy do
Expand Down

0 comments on commit dce1e25

Please sign in to comment.