Class: Sequent::Util::DryRun::Result
- Inherits:
-
Object
- Object
- Sequent::Util::DryRun::Result
- Defined in:
- lib/sequent/util/dry_run.rb
Overview
Contains the result of a dry run.
Defined Under Namespace
Classes: EventCalledHandlers
Instance Method Summary collapse
-
#initialize ⇒ Result
constructor
A new instance of Result.
- #invoked_projector(event_invoked_handler) ⇒ Object
- #invoked_workflow(event_invoked_handler) ⇒ Object
-
#print(io) ⇒ Object
Prints the output from #tree to the given ‘io`.
- #published_command_with_events(command, events) ⇒ Object
-
#tree ⇒ Object
Returns the command with events as a tree structure.
Constructor Details
#initialize ⇒ Result
Returns a new instance of Result.
94 95 96 97 98 |
# File 'lib/sequent/util/dry_run.rb', line 94 def initialize @command_with_events = {} @event_invoked_projectors = [] @event_invoked_workflows = [] end |
Instance Method Details
#invoked_projector(event_invoked_handler) ⇒ Object
100 101 102 |
# 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) ⇒ Object
104 105 106 |
# File 'lib/sequent/util/dry_run.rb', line 104 def invoked_workflow(event_invoked_handler) event_invoked_workflows << event_invoked_handler end |
#print(io) ⇒ Object
Prints the output from #tree to the given ‘io`
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/sequent/util/dry_run.rb', line 145 def print(io) tree.each_with_index do |(command, event_called_handlerss), index| io.puts '+++++++++++++++++++++++++++++++++++' if index == 0 io.puts "Command: #{command.class} resulted in #{event_called_handlerss.length} events" event_called_handlerss.each_with_index do |event_called_handlers, i| io.puts '' if i > 0 io.puts "-- Event #{event_called_handlers.event.class} was handled by:" io.puts "-- Projectors: [#{event_called_handlers.projectors.join(', ')}]" io.puts "-- Workflows: [#{event_called_handlers.workflows.join(', ')}]" end io.puts '+++++++++++++++++++++++++++++++++++' end end |
#published_command_with_events(command, events) ⇒ Object
108 109 110 |
# File 'lib/sequent/util/dry_run.rb', line 108 def published_command_with_events(command, events) command_with_events[command] = events end |
#tree ⇒ Object
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.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# 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 |