class Strategy::Step

Step encapsulates a single step in a larger plan of execution. A step contains a set of actions, which are the actual pieces of executable code, as well as a high-level description of what the step accomplishes.

Attributes

actions[R]
description[R]

Public Class Methods

new(description) click to toggle source

Creates a new Step, which can later be added to a Plan.

Parameters:

description

The description of the step. This is a high-level description of what the step is supposed to accomplish.

# File lib/strategy/step.rb, line 15
def initialize description
  @description = description
  @actions = []
end

Public Instance Methods

action(&block) click to toggle source

Adds a new action to the step. Actions are given as a code block, and will be executed in the order they are added (if the step is executed).

# File lib/strategy/step.rb, line 22
def action &block
  if block.nil?
    raise RuntimeError, 'expected a block but none given'
  end
  @actions << block
end
execute!() click to toggle source

Execute all actions sequentially as they appear in the Step.

# File lib/strategy/step.rb, line 30
def execute!
  @actions.each do |action|
    action.call
  end
end