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.bar
  end

end

The order of which handler block is executed first is not guaranteed.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(host_class) ⇒ Object



53
54
55
# File 'lib/sequent/core/helpers/message_handler.rb', line 53

def self.included(host_class)
  host_class.extend(ClassMethods)
end

Instance Method Details

#handle_message(message) ⇒ Object



57
58
59
60
# File 'lib/sequent/core/helpers/message_handler.rb', line 57

def handle_message(message)
  handlers = self.class.message_mapping[message.class]
  handlers.each { |handler| self.instance_exec(message, &handler) } if handlers
end