Class: Sequent::Core::BaseCommandHandler

Inherits:
Object
  • Object
show all
Includes:
Helpers::SelfApplier, Helpers::UuidHelper
Defined in:
lib/sequent/core/base_command_handler.rb

Overview

Base class for command handlers CommandHandlers are responsible for propagating a command to the correct Sequent::Core::AggregateRoot or creating a new one. For example:

class InvoiceCommandHandler < Sequent::Core::BaseCommandHandler
  on CreateInvoiceCommand do |command|
    repository.add_aggregate Invoice.new(command.aggregate_id)
  end

  on PayInvoiceCommand do |command|
    do_with_aggregate(command, Invoice) {|invoice|invoice.pay(command.pay_date)}
  end
end

Direct Known Subclasses

AggregateSnapshotter

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::SelfApplier

#handle_message, included

Methods included from Helpers::UuidHelper

new_uuid

Constructor Details

#initialize(repository = Sequent.configuration.aggregate_repository) ⇒ BaseCommandHandler

Returns a new instance of BaseCommandHandler.



25
26
27
# File 'lib/sequent/core/base_command_handler.rb', line 25

def initialize(repository = Sequent.configuration.aggregate_repository)
  @repository = repository
end

Instance Attribute Details

#repositoryObject

Returns the value of attribute repository.



23
24
25
# File 'lib/sequent/core/base_command_handler.rb', line 23

def repository
  @repository
end

Instance Method Details

#handles_message?(command) ⇒ Boolean

Returns:



29
30
31
# File 'lib/sequent/core/base_command_handler.rb', line 29

def handles_message?(command)
  self.class.message_mapping.keys.include? command.class
end