Class: Brut::TUI::Script::BlockStep

Inherits:
Step
  • Object
show all
Defined in:
lib/brut/tui/script/block_step.rb

Overview

A step whose behavior is a given block of code. Fires Events::StepStarted before the code executes and Events::StepCompleted only if the block completes without an exception being thrown.

Constant Summary

Constants inherited from Step

Step::Events

Instance Attribute Summary

Attributes inherited from Step

#description

Instance Method Summary collapse

Constructor Details

#initialize(event_loop, description, &block) ⇒ BlockStep

Returns a new instance of BlockStep.



6
7
8
9
# File 'lib/brut/tui/script/block_step.rb', line 6

def initialize(event_loop, description, &block)
  super(event_loop, description)
  @block = block
end

Instance Method Details

#run!Object



11
12
13
14
15
16
# File 'lib/brut/tui/script/block_step.rb', line 11

def run!
  event_loop << Events::StepStarted.new(step: self)
  @block.().tap {
    event_loop << Events::StepCompleted.new(step: self)
  }
end