Module: Sequent::Core::Helpers::MessageHandler
- Included in:
- AggregateRoot, BaseCommandHandler, Projector, Workflow
- Defined in:
- lib/sequent/core/helpers/message_handler.rb
Overview
Creates ability to use DSL like:
class MyProjector < Sequent::Projector
on MyEvent do |event|
@foo = event.foo
end
end
If you extend from Sequent::AggregateRoot
, Sequent::Projector
, Sequent::Workflow
or Sequent::CommandHandler
you will get this functionality for free.
It is possible to register multiple handler blocks in the same MessageHandler
class MyProjector < Sequent::Projector
on MyEvent do |event|
@foo = event.foo
end
on MyEvent, OtherEvent do |event|
@bar = event.
end
end
The order of which handler block is executed first is not guaranteed.
Defined Under Namespace
Modules: ClassMethods Classes: OnArgumentsValidator
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(host_class) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/sequent/core/helpers/message_handler.rb', line 95 def self.included(host_class) host_class.extend(ClassMethods) host_class.extend(MessageMatchers) host_class.extend(AttrMatchers) host_class.class_attribute :option_registry, default: MessageHandlerOptionRegistry.new end |
Instance Method Details
#dispatch_message(message, handlers) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/sequent/core/helpers/message_handler.rb', line 108 def (, handlers) handlers.each do |handler| if Sequent.logger.debug? Sequent.logger.debug("[MessageHandler] Handler #{self.class} handling #{.class}") end instance_exec(, &handler) end end |
#handle_message(message) ⇒ Object
103 104 105 106 |
# File 'lib/sequent/core/helpers/message_handler.rb', line 103 def () handlers = self.class..() (, handlers) unless handlers.empty? end |