Class: StepMachine::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/step_machine/runner.rb

Defined Under Namespace

Classes: FailureTreatment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

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

#continueObject

Returns the value of attribute continue.



4
5
6
# File 'lib/step_machine/runner.rb', line 4

def continue
  @continue
end

#failed_stepObject (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_stepObject

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_stepObject

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_whatObject

Returns the value of attribute repeat_what.



4
5
6
# File 'lib/step_machine/runner.rb', line 4

def repeat_what
  @repeat_what
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/step_machine/runner.rb', line 5

def status
  @status
end

#times_to_repeatObject

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(options = {}, &block)
	@after_each_step << options.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(options = {}, &block)
	@before_each_step << options.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(options = {}, &block)			
	@failure_treatments << FailureTreatment.new(self, block, options)
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(options = {})
    if group = group(options[:group])
      assign_group_first_step(group)
      return if @next_step.group != group
    end

    assign_from_step(options[:from]) unless options[: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 == options[:upto]

    run(options) 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