Class: Methodical::Walkthrough
- Inherits:
-
Array
- Object
- Array
- Methodical::Walkthrough
- Extended by:
- Forwardable
- Defined in:
- lib/methodical/walkthrough.rb
Instance Attribute Summary collapse
-
#baton ⇒ Object
readonly
Returns the value of attribute baton.
-
#checklist ⇒ Object
readonly
Returns the value of attribute checklist.
-
#decisive_index ⇒ Object
readonly
Returns the value of attribute decisive_index.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#last_step_index ⇒ Object
readonly
Returns the value of attribute last_step_index.
-
#next_step_index ⇒ Object
readonly
Returns the value of attribute next_step_index.
Instance Method Summary collapse
- #basic_report ⇒ Object
- #decided? ⇒ Boolean
- #decisive_step ⇒ Object
- #done? ⇒ Boolean (also: #finished?)
- #failed? ⇒ Boolean
- #failed_steps ⇒ Object
- #halted? ⇒ Boolean
- #in_progress? ⇒ Boolean
-
#initialize(checklist, baton = nil) ⇒ Walkthrough
constructor
A new instance of Walkthrough.
- #inspect ⇒ Object
- #next!(baton = @baton, raise_on_error = false) {|_self, index, action_item, baton| ... } ⇒ Object
- #perform!(baton = @baton, raise_on_error = false, &block) ⇒ Object
- #started? ⇒ Boolean
- #status ⇒ Object
- #succeeded? ⇒ Boolean
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
#baton ⇒ Object (readonly)
Returns the value of attribute baton.
11 12 13 |
# File 'lib/methodical/walkthrough.rb', line 11 def baton @baton end |
#checklist ⇒ Object (readonly)
Returns the value of attribute checklist.
8 9 10 |
# File 'lib/methodical/walkthrough.rb', line 8 def checklist @checklist end |
#decisive_index ⇒ Object (readonly)
Returns the value of attribute decisive_index.
13 14 15 |
# File 'lib/methodical/walkthrough.rb', line 13 def decisive_index @decisive_index end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
12 13 14 |
# File 'lib/methodical/walkthrough.rb', line 12 def index @index end |
#last_step_index ⇒ Object (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_index ⇒ Object (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_report ⇒ Object
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
95 96 97 |
# File 'lib/methodical/walkthrough.rb', line 95 def decided? !!decisive_index end |
#decisive_step ⇒ Object
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?
90 91 92 |
# File 'lib/methodical/walkthrough.rb', line 90 def done? index >= size end |
#failed? ⇒ Boolean
81 82 83 |
# File 'lib/methodical/walkthrough.rb', line 81 def failed? decided? && !decisive_step.done_and_ok? end |
#failed_steps ⇒ Object
65 66 67 |
# File 'lib/methodical/walkthrough.rb', line 65 def failed_steps find_all{|step| step.failed?} end |
#halted? ⇒ Boolean
99 100 101 |
# File 'lib/methodical/walkthrough.rb', line 99 def halted? @halted end |
#in_progress? ⇒ Boolean
103 104 105 |
# File 'lib/methodical/walkthrough.rb', line 103 def in_progress? started? && !done? end |
#inspect ⇒ Object
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
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
107 108 109 |
# File 'lib/methodical/walkthrough.rb', line 107 def started? @started end |
#status ⇒ Object
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
85 86 87 88 |
# File 'lib/methodical/walkthrough.rb', line 85 def succeeded? return true if empty? decided? && decisive_step.done_and_ok? end |