class Sequent::Util::DryRun::Result

Contains the result of a dry run.

@see tree @see print

Constants

EventCalledHandlers

Attributes

command_with_events[R]
event_invoked_projectors[R]
event_invoked_workflows[R]

Public Class Methods

new() click to toggle source
# File lib/sequent/util/dry_run.rb, line 94
def initialize
  @command_with_events = {}
  @event_invoked_projectors = []
  @event_invoked_workflows = []
end

Public Instance Methods

invoked_projector(event_invoked_handler) click to toggle source
# File lib/sequent/util/dry_run.rb, line 100
def invoked_projector(event_invoked_handler)
  event_invoked_projectors << event_invoked_handler
end
invoked_workflow(event_invoked_handler) click to toggle source
# File lib/sequent/util/dry_run.rb, line 104
def invoked_workflow(event_invoked_handler)
  event_invoked_workflows << event_invoked_handler
end
print(io) click to toggle source

Prints the output from tree to the given ‘io`

published_command_with_events(command, events) click to toggle source
# File lib/sequent/util/dry_run.rb, line 108
def published_command_with_events(command, events)
  command_with_events[command] = events
end
tree() click to toggle source

Returns the command with events as a tree structure.

{

command => [
  EventCalledHandlers,
  EventCalledHandlers,
  EventCalledHandlers,
]

}

The EventCalledHandlers contains an Event with the lists of ‘Sequent::Projector`s and `Sequent::Workflow`s that were called.

# File lib/sequent/util/dry_run.rb, line 127
def tree
  command_with_events.reduce({}) do |memo, (command, events)|
    events_to_handlers = events.map do |event|
      for_current_event = ->(pair) { pair.event == event }
      EventCalledHandlers.new(
        event,
        event_invoked_projectors.select(&for_current_event).map(&:handler),
        event_invoked_workflows.select(&for_current_event).map(&:handler),
      )
    end
    memo[command] = events_to_handlers
    memo
  end
end