Class: StepMachine::Runner
- Inherits:
-
Object
- Object
- StepMachine::Runner
- Defined in:
- lib/step_machine/runner.rb
Defined Under Namespace
Classes: FailureTreatment
Instance Attribute Summary collapse
-
#continue ⇒ Object
Returns the value of attribute continue.
-
#failed_step ⇒ Object
readonly
Returns the value of attribute failed_step.
-
#first_step ⇒ Object
Returns the value of attribute first_step.
-
#next_step ⇒ Object
Returns the value of attribute next_step.
-
#repeat_what ⇒ Object
Returns the value of attribute repeat_what.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#times_to_repeat ⇒ Object
Returns the value of attribute times_to_repeat.
Instance Method Summary collapse
- #after_each_step(options = {}, &block) ⇒ Object
- #before_each_step(options = {}, &block) ⇒ Object
- #group(name) ⇒ Object
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #on_step_failure(options = {}, &block) ⇒ Object
- #run(options = {}) ⇒ Object
- #step(name, &block) ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
7 8 9 10 11 12 13 14 |
# File 'lib/step_machine/runner.rb', line 7 def initialize @steps = [] @groups = [] @failure_treatments = [] @before_each_step = [] @after_each_step = [] @times_to_repeat = -1 end |
Instance Attribute Details
#continue ⇒ Object
Returns the value of attribute continue.
4 5 6 |
# File 'lib/step_machine/runner.rb', line 4 def continue @continue end |
#failed_step ⇒ Object (readonly)
Returns the value of attribute failed_step.
5 6 7 |
# File 'lib/step_machine/runner.rb', line 5 def failed_step @failed_step end |
#first_step ⇒ Object
Returns the value of attribute first_step.
4 5 6 |
# File 'lib/step_machine/runner.rb', line 4 def first_step @first_step end |
#next_step ⇒ Object
Returns the value of attribute next_step.
4 5 6 |
# File 'lib/step_machine/runner.rb', line 4 def next_step @next_step end |
#repeat_what ⇒ Object
Returns the value of attribute repeat_what.
4 5 6 |
# File 'lib/step_machine/runner.rb', line 4 def repeat_what @repeat_what end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/step_machine/runner.rb', line 5 def status @status end |
#times_to_repeat ⇒ Object
Returns the value of attribute times_to_repeat.
4 5 6 |
# File 'lib/step_machine/runner.rb', line 4 def times_to_repeat @times_to_repeat end |
Instance Method Details
#after_each_step(options = {}, &block) ⇒ Object
41 42 43 |
# File 'lib/step_machine/runner.rb', line 41 def after_each_step( = {}, &block) @after_each_step << .merge(:block => block) end |
#before_each_step(options = {}, &block) ⇒ Object
37 38 39 |
# File 'lib/step_machine/runner.rb', line 37 def before_each_step( = {}, &block) @before_each_step << .merge(:block => block) end |
#group(name) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/step_machine/runner.rb', line 25 def group(name) return nil if name.nil? @current_group = group = @groups.detect {|g| g.name == name} || create_group(name) yield if block_given? @current_group = nil group end |
#on_step_failure(options = {}, &block) ⇒ Object
33 34 35 |
# File 'lib/step_machine/runner.rb', line 33 def on_step_failure( = {}, &block) @failure_treatments << FailureTreatment.new(self, block, ) end |
#run(options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/step_machine/runner.rb', line 49 def run( = {}) if group = group([:group]) assign_group_first_step(group) return if @next_step.group != group end assign_from_step([:from]) unless [:from].nil? @continue = nil step = @next_step @status ||= :success execute_before_each_step(step) unless step.perform @failed_step = step return repeat if repeat? execute_step_failures(step) return run if @continue @status = :failure return end execute_after_each_step(step) return if step.name == [:upto] run() if @next_step = step.next end |
#step(name, &block) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/step_machine/runner.rb', line 16 def step(name, &block) step = get_step(name) || create_step(name) step.block = block if block @first_step ||= step @next_step ||= @first_step step end |