Class: Methodical::Walkthrough

Inherits:
Array
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/methodical/walkthrough.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(checklist, baton = nil) ⇒ Walkthrough

Returns a new instance of Walkthrough.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/methodical/walkthrough.rb', line 17

def initialize(checklist, baton=nil)
  @checklist       = checklist
  @continue        = true
  @baton           = baton
  @index           = 0
  @decisive_index  = nil
  @halted          = false
  @started         = false
  super(Array.new(checklist.map{|ai| ai.clone}))
  each do |step|
    step.walkthrough = self
  end
end

Instance Attribute Details

#batonObject (readonly)

Returns the value of attribute baton.



11
12
13
# File 'lib/methodical/walkthrough.rb', line 11

def baton
  @baton
end

#checklistObject (readonly)

Returns the value of attribute checklist.



8
9
10
# File 'lib/methodical/walkthrough.rb', line 8

def checklist
  @checklist
end

#decisive_indexObject (readonly)

Returns the value of attribute decisive_index.



13
14
15
# File 'lib/methodical/walkthrough.rb', line 13

def decisive_index
  @decisive_index
end

#indexObject (readonly)

Returns the value of attribute index.



12
13
14
# File 'lib/methodical/walkthrough.rb', line 12

def index
  @index
end

#last_step_indexObject (readonly)

Returns the value of attribute last_step_index.



10
11
12
# File 'lib/methodical/walkthrough.rb', line 10

def last_step_index
  @last_step_index
end

#next_step_indexObject (readonly)

Returns the value of attribute next_step_index.



9
10
11
# File 'lib/methodical/walkthrough.rb', line 9

def next_step_index
  @next_step_index
end

Instance Method Details

#basic_reportObject



59
60
61
62
63
# File 'lib/methodical/walkthrough.rb', line 59

def basic_report
  inject(""){|report, action_item| 
    report << action_item.synopsis << "\n"
  }
end

#decided?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/methodical/walkthrough.rb', line 95

def decided?
  !!decisive_index
end

#decisive_stepObject



69
70
71
# File 'lib/methodical/walkthrough.rb', line 69

def decisive_step
  decided? ? fetch(decisive_index) : nil
end

#done?Boolean Also known as: finished?

Returns:

  • (Boolean)


90
91
92
# File 'lib/methodical/walkthrough.rb', line 90

def done?
  index >= size
end

#failed?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/methodical/walkthrough.rb', line 81

def failed?
  decided? && !decisive_step.done_and_ok?
end

#failed_stepsObject



65
66
67
# File 'lib/methodical/walkthrough.rb', line 65

def failed_steps
  find_all{|step| step.failed?}
end

#halted?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/methodical/walkthrough.rb', line 99

def halted?
  @halted
end

#in_progress?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/methodical/walkthrough.rb', line 103

def in_progress?
  started? && !done?
end

#inspectObject



55
56
57
# File 'lib/methodical/walkthrough.rb', line 55

def inspect
  "##<#{self.class.name}:#{title}:#{object_id}>"
end

#next!(baton = @baton, raise_on_error = false) {|_self, index, action_item, baton| ... } ⇒ Object

Yields:

Yield Parameters:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/methodical/walkthrough.rb', line 38

def next!(baton=@baton, raise_on_error=false)
  raise "Already performed" if done?

  @started = true

  action_item = fetch(index)
  yield(self, index, action_item, baton) if block_given?

  execute_or_update_step(action_item, baton, raise_on_error)

  @decisive_index = index if action_item.decisive?
  @halted         = true if action_item.halted?

  yield(self, index, action_item, baton) if block_given?
  advance!
end

#perform!(baton = @baton, raise_on_error = false, &block) ⇒ Object



31
32
33
34
35
36
# File 'lib/methodical/walkthrough.rb', line 31

def perform!(baton=@baton, raise_on_error=false, &block)
  @baton  = baton
  until done?
    self.next!(baton, raise_on_error, &block)
  end
end

#started?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/methodical/walkthrough.rb', line 107

def started?
  @started
end

#statusObject



73
74
75
76
77
78
79
# File 'lib/methodical/walkthrough.rb', line 73

def status
  if !started? then :not_started
  elsif !decided? then :in_progress
  elsif succeeded? then :succeeded
  else  :failed
  end
end

#succeeded?Boolean

Returns:

  • (Boolean)


85
86
87
88
# File 'lib/methodical/walkthrough.rb', line 85

def succeeded?
  return true if empty?
  decided? && decisive_step.done_and_ok?
end