Class: Strategy::Step
- Inherits:
-
Object
- Object
- Strategy::Step
- 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
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#action(&block) ⇒ Object
Adds a new action to the step.
-
#execute! ⇒ Object
Execute all actions sequentially as they appear in the Step.
-
#initialize(name) ⇒ Step
constructor
Creates a new Step, which can later be added to a Plan.
Constructor Details
#initialize(name) ⇒ Step
Creates a new Step, which can later be added to a Plan.
Parameters:
- name
-
The name 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 name @name = name @actions = [] end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
6 7 8 |
# File 'lib/strategy/step.rb', line 6 def actions @actions end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/strategy/step.rb', line 6 def name @name 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 |
# File 'lib/strategy/step.rb', line 22 def action &block @actions << block end |
#execute! ⇒ Object
Execute all actions sequentially as they appear in the Step.
27 28 29 30 31 |
# File 'lib/strategy/step.rb', line 27 def execute! @actions.each do |action| action.call end end |