Class: Strategy::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/strategy/step.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description) ⇒ Step

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.



15
16
17
18
# File 'lib/strategy/step.rb', line 15

def initialize description
  @description = description
  @actions = []
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



6
7
8
# File 'lib/strategy/step.rb', line 6

def actions
  @actions
end

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/strategy/step.rb', line 6

def description
  @description
end

Instance Method Details

#action(&block) ⇒ Object

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).



22
23
24
25
26
27
# 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!Object

Execute all actions sequentially as they appear in the Step.



30
31
32
33
34
# File 'lib/strategy/step.rb', line 30

def execute!
  @actions.each do |action|
    action.call
  end
end