class Aggregates::DomainExecutor

Combines a storage backend and a domain in order to execute that domain.

Attributes

domain[R]
storage_backend[R]

Public Class Methods

new(storage_backend, domain) click to toggle source
# File lib/aggregates/domain_executor.rb, line 11
def initialize(storage_backend, domain)
  @aggregate_repository = AggregateRepository.new(storage_backend)
  @dispatcher = CommandDispatcher.new(domain.command_processors, domain.command_filters)
  @storage_backend = storage_backend
end

Public Instance Methods

audit(type, aggregate_id) click to toggle source
# File lib/aggregates/domain_executor.rb, line 23
def audit(type, aggregate_id)
  Auditor.new(@storage_backend, type, aggregate_id)
end
execute_command(command) click to toggle source
# File lib/aggregates/domain_executor.rb, line 17
def execute_command(command)
  command.validate!
  command_execution = CommandExecution.new(@aggregate_repository, command)
  dispatch(command_execution)
end

Private Instance Methods

dispatch(command_execution) click to toggle source
# File lib/aggregates/domain_executor.rb, line 33
def dispatch(command_execution)
  result = @dispatcher.execute_command(command_execution)
  store_command(command_execution.command) if result
  result
end
store_command(command) click to toggle source
# File lib/aggregates/domain_executor.rb, line 29
def store_command(command)
  @storage_backend.store_command(command)
end