Class: Aggregates::DomainExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/aggregates/domain_executor.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage_backend, domain) ⇒ DomainExecutor

Returns a new instance of DomainExecutor.



11
12
13
14
15
# 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

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



9
10
11
# File 'lib/aggregates/domain_executor.rb', line 9

def domain
  @domain
end

#storage_backendObject (readonly)

Returns the value of attribute storage_backend.



9
10
11
# File 'lib/aggregates/domain_executor.rb', line 9

def storage_backend
  @storage_backend
end

Instance Method Details

#audit(type, aggregate_id) ⇒ Object



23
24
25
# File 'lib/aggregates/domain_executor.rb', line 23

def audit(type, aggregate_id)
  Auditor.new(@storage_backend, type, aggregate_id)
end

#execute_command(command) ⇒ Object



17
18
19
20
21
# 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