Class: Checklist
- Inherits:
-
Object
- Object
- Checklist
- Defined in:
- lib/checklist.rb,
lib/checklist/ui.rb,
lib/checklist/step.rb,
lib/checklist/version.rb,
lib/checklist/wrapper.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#ui ⇒ Object
readonly
Returns the value of attribute ui.
Class Method Summary collapse
-
.checklist(*args) {|cl| ... } ⇒ Object
Yields a new checklist to block and runs it.
-
.step(challenge, response, description = nil, &block) ⇒ Object
Create a new Step instance.
Instance Method Summary collapse
-
#<<(step) ⇒ Object
appendd a Checklist::Step to the checklist.
-
#close! ⇒ Object
Finish the checklist, print and return outstanding steps.
-
#completed ⇒ Object
Number of completed steps or nil if list is not open.
-
#completed? ⇒ Boolean
true if checklist is started and all steps are completed_steps.
-
#initialize(name, options = {}) ⇒ Checklist
constructor
A new instance of Checklist.
-
#length ⇒ Object
Number of defined steps.
- #open! ⇒ Object
-
#open? ⇒ Boolean
true if checklist is started.
-
#remaining ⇒ Object
Number of remaining steps or nil if list is not open.
-
#run! ⇒ Object
Run the whole thing.
-
#step(challenge, response, description = nil, &code) ⇒ Object
create new Checklist::Step and add it to the checklist.
-
#step! ⇒ Object
Execute one step of the checklist.
Constructor Details
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
9 10 11 |
# File 'lib/checklist.rb', line 9 def current @current end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/checklist.rb', line 9 def name @name end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
9 10 11 |
# File 'lib/checklist.rb', line 9 def steps @steps end |
#ui ⇒ Object (readonly)
Returns the value of attribute ui.
9 10 11 |
# File 'lib/checklist.rb', line 9 def ui @ui end |
Class Method Details
.checklist(*args) {|cl| ... } ⇒ Object
Yields a new checklist to block and runs it
3 4 5 6 7 8 |
# File 'lib/checklist/wrapper.rb', line 3 def self.checklist(*args) raise ArgumentError, 'need a block' unless block_given? cl = self.new(*args) yield cl cl.run! end |
.step(challenge, response, description = nil, &block) ⇒ Object
Create a new Step instance
16 17 18 19 |
# File 'lib/checklist/step.rb', line 16 def self.step(challenge, response, description=nil, &block) raise ArgumentError, 'need a block' unless block_given? Step.new(challenge, response, description, block) end |
Instance Method Details
#<<(step) ⇒ Object
appendd a Checklist::Step to the checklist
21 22 23 24 25 |
# File 'lib/checklist.rb', line 21 def <<(step) raise RuntimeError, 'List is open' if open? step.must_be_a(Step) steps << step end |
#close! ⇒ Object
Finish the checklist, print and return outstanding steps
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/checklist.rb', line 77 def close! raise RuntimeError, 'Checklist is not open' unless open? if completed? ui.complete(self) else ui.incomplete(self, remaining_steps) end rv = remaining_steps self.current = self.remaining_steps = self.completed_steps = nil rv end |
#completed ⇒ Object
Number of completed steps or nil if list is not open
53 54 55 |
# File 'lib/checklist.rb', line 53 def completed completed_steps and completed_steps.length end |
#completed? ⇒ Boolean
true if checklist is started and all steps are completed_steps
38 39 40 |
# File 'lib/checklist.rb', line 38 def completed? remaining_steps && remaining_steps.empty? end |
#length ⇒ Object
Number of defined steps
43 44 45 |
# File 'lib/checklist.rb', line 43 def length steps.length end |
#open! ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/checklist.rb', line 57 def open! raise RuntimeError, "Checklist is already open" if open? ui.header(self) self.remaining_steps = steps.clone self.completed_steps = [] self end |
#open? ⇒ Boolean
true if checklist is started
33 34 35 |
# File 'lib/checklist.rb', line 33 def open? !!remaining_steps end |
#remaining ⇒ Object
Number of remaining steps or nil if list is not open
48 49 50 |
# File 'lib/checklist.rb', line 48 def remaining remaining_steps and remaining_steps.length end |
#run! ⇒ Object
Run the whole thing
93 94 95 96 97 98 99 |
# File 'lib/checklist.rb', line 93 def run! open! step! until completed? self ensure close! end |
#step(challenge, response, description = nil, &code) ⇒ Object
create new Checklist::Step and add it to the checklist
28 29 30 |
# File 'lib/checklist.rb', line 28 def step(challenge, response, description=nil, &code) self << Checklist::step(challenge, response, description, &code) end |
#step! ⇒ Object
Execute one step of the checklist
66 67 68 69 70 71 72 73 74 |
# File 'lib/checklist.rb', line 66 def step! raise RuntimeError, 'Checklist is not open' unless open? raise RuntimeError, 'Checklist is completed' if completed? self.current = remaining_steps.first ui.start(current) current.run! ui.finish(current) completed_steps << remaining_steps.shift end |