Class: Midnight::Mongoid::Interactor

Inherits:
Object
  • Object
show all
Defined in:
lib/midnight/mongoid/interactor.rb

Instance Method Summary collapse

Constructor Details

#initialize(aggregate_key:, build_aggregate:, event_handler: Commons::NULL_EVENT_HANDLER, command_validator: DEFAULT_COMMAND_VALIDATOR, state_persistence: State, advance_state_metadata: lambda(&:advance_metadata), save_state: lambda(&:save!)) ⇒ Interactor

Returns a new instance of Interactor.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/midnight/mongoid/interactor.rb', line 9

def initialize(\
  aggregate_key:,
  build_aggregate:,
  event_handler: Commons::NULL_EVENT_HANDLER,
  command_validator: DEFAULT_COMMAND_VALIDATOR,
  state_persistence: State,
  advance_state_metadata: lambda(&:advance_metadata),
  save_state: lambda(&:save!)
)
  @aggregate_key = aggregate_key
  @build_aggregate = build_aggregate
  @event_handler = event_handler
  @command_validator = command_validator
  @state_persistence = state_persistence
  @advance_state_metadata = 
  @save_state = save_state
  freeze
end

Instance Method Details

#call(*commands) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/midnight/mongoid/interactor.rb', line 28

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