Module: AggregateRoot::OnDSL
- Defined in:
- lib/aggregate_root.rb
Constant Summary collapse
- ANONYMOUS_CLASS =
"#<Class:".freeze
Instance Method Summary collapse
Instance Method Details
#on(*event_klasses, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/aggregate_root.rb', line 16 def on(*event_klasses, &block) event_klasses.each do |event_klass| name = event_klass.to_s raise(ArgumentError, "Anonymous class is missing name") if name.start_with? ANONYMOUS_CLASS handler_name = "on_#{name}" define_method(handler_name, &block) @on_methods ||= {} @on_methods[name] = handler_name private(handler_name) end end |
#on_methods ⇒ Object
29 30 31 32 |
# File 'lib/aggregate_root.rb', line 29 def on_methods @on_methods ||= {} (superclass.respond_to?(:on_methods) ? superclass.on_methods : {}).merge(@on_methods) end |