Class: Diddy::Steps
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#current_step ⇒ Object
Returns the value of attribute current_step.
-
#sub_steps ⇒ Object
Returns the value of attribute sub_steps.
Class Method Summary collapse
-
.definition(description) ⇒ Object
Returns proc for step.
-
.has_step?(description) ⇒ Boolean
Checks if a step is defined.
-
.step(description, &block) ⇒ Object
Describes a step.
-
.steps ⇒ Object
Returns the defined steps.
Instance Method Summary collapse
-
#initialize(shared_scope) ⇒ Steps
constructor
A new instance of Steps.
-
#reset! ⇒ Object
Reset me.
-
#shared ⇒ Object
Returns shared scope.
-
#sub_step(description, &block) ⇒ Object
Adds a sub_step.
Methods included from Helpers
Constructor Details
#initialize(shared_scope) ⇒ Steps
Returns a new instance of Steps.
8 9 10 |
# File 'lib/diddy/steps.rb', line 8 def initialize(shared_scope) @shared_scope = shared_scope end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
6 7 8 |
# File 'lib/diddy/steps.rb', line 6 def context @context end |
#current_step ⇒ Object
Returns the value of attribute current_step.
6 7 8 |
# File 'lib/diddy/steps.rb', line 6 def current_step @current_step end |
#sub_steps ⇒ Object
Returns the value of attribute sub_steps.
6 7 8 |
# File 'lib/diddy/steps.rb', line 6 def sub_steps @sub_steps end |
Class Method Details
.definition(description) ⇒ Object
Returns proc for step
59 60 61 |
# File 'lib/diddy/steps.rb', line 59 def self.definition(description) @steps[description] end |
.has_step?(description) ⇒ Boolean
Checks if a step is defined
52 53 54 |
# File 'lib/diddy/steps.rb', line 52 def self.has_step?(description) @steps && @steps.has_key?(description) end |
.step(description, &block) ⇒ Object
Describes a step
step('Do something crazy') do
...
a == true
end
Steps must return TRUE to keep the script running. When a step returns a FALSE, it will stop the script.
It is also to use sub_steps (not to confuse with dubstep).
step('Do something crazy') do
sub_step('Eat brains') do
a == true
end
sub_step('Go insane') do
b == true
end
end
In the case above, every sub_step needs to return true.
37 38 39 40 |
# File 'lib/diddy/steps.rb', line 37 def self.step(description, &block) @steps ||= {} @steps[description] = block end |
.steps ⇒ Object
Returns the defined steps
45 46 47 |
# File 'lib/diddy/steps.rb', line 45 def self.steps @steps end |
Instance Method Details
#reset! ⇒ Object
Reset me
100 101 102 103 104 105 106 |
# File 'lib/diddy/steps.rb', line 100 def reset! instance_variables.each do |var| unless %w(@shared_scope).include?(var.to_s) remove_instance_variable(var) end end end |
#shared ⇒ Object
Returns shared scope
66 67 68 |
# File 'lib/diddy/steps.rb', line 66 def shared @shared_scope end |
#sub_step(description, &block) ⇒ Object
Adds a sub_step
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/diddy/steps.rb', line 73 def sub_step(description, &block) # print pending to screen print("\n") print(blue(" . #{description}")) result_hash = { description: description, valid: false } self.sub_steps << result_hash # yield the block valid = yield(block) # jump back to beginning of line print("\r") # print out success or failure if valid print(green(" ✓ #{description}")) else print(red(bold(" ✕ #{description}"))) end result_hash[:valid] = valid end |