Class: Midnight::Rails::ActiveRecordInteractor

Inherits:
Object
  • Object
show all
Defined in:
lib/midnight/rails/active_record_interactor.rb

Overview

noinspection RubyParameterNamingConvention

Instance Method Summary collapse

Constructor Details

#initialize(aggregate_key:, build_aggregate:, transaction_handler: Commons::NULL_EVENT_HANDLER, committed_handler: Commons::NULL_EVENT_HANDLER, command_validator: DEFAULT_COMMAND_VALIDATOR, state_persistence: StateAdapter.new( active_record: DefaultState ), advance_state_metadata: lambda(&:advance_metadata), save_state: lambda(&:save!)) ⇒ ActiveRecordInteractor

Returns a new instance of ActiveRecordInteractor.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/midnight/rails/active_record_interactor.rb', line 9

def initialize(
  aggregate_key:,
  build_aggregate:,
  transaction_handler: Commons::NULL_EVENT_HANDLER,
  committed_handler: Commons::NULL_EVENT_HANDLER,
  command_validator: DEFAULT_COMMAND_VALIDATOR,
  state_persistence: StateAdapter.new(
    active_record: DefaultState
  ),
  advance_state_metadata: lambda(&:advance_metadata),
  save_state: lambda(&:save!)
)
  @aggregate_key = aggregate_key
  @build_aggregate = build_aggregate
  @transaction_handler = transaction_handler
  @committed_handler = committed_handler
  @command_validator = command_validator
  @state_persistence = state_persistence
  @advance_state_metadata = 
  @save_state = save_state
  freeze
end

Instance Method Details

#call(*commands) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/midnight/rails/active_record_interactor.rb', line 32

def call(*commands)
  commands.each(&@command_validator)
  transaction do |aggregate|
    commands.each(&aggregate.method(:dispatch))
    aggregate.pending_events
  end
end