Class: Project
- Inherits:
-
Object
- Object
- Project
- Defined in:
- lib/wrkflo/project.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#steps ⇒ Object
Returns the value of attribute steps.
Instance Method Summary collapse
-
#initialize(name, steps) ⇒ Project
constructor
A new instance of Project.
-
#log(message) ⇒ Object
Post a message to the terminal with some identifying information.
-
#run ⇒ Object
Run each step in the order they are specified.
-
#unrun ⇒ Object
Undo the steps in reverse order.
Constructor Details
#initialize(name, steps) ⇒ Project
6 7 8 9 10 11 12 13 |
# File 'lib/wrkflo/project.rb', line 6 def initialize name, steps # The name of this project workflow @name = name # The steps that make up this workflow @steps = steps.map{ |name, config| Step.create(name, config, self) } # The step currently being executed @current_step = 0 end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/wrkflo/project.rb', line 4 def name @name end |
#steps ⇒ Object
Returns the value of attribute steps.
4 5 6 |
# File 'lib/wrkflo/project.rb', line 4 def steps @steps end |
Instance Method Details
#log(message) ⇒ Object
Post a message to the terminal with some identifying information
52 53 54 |
# File 'lib/wrkflo/project.rb', line 52 def log puts " - Step ##{@current_step_num} (#{@current_step.name}): #{message}" end |
#run ⇒ Object
Run each step in the order they are specified
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/wrkflo/project.rb', line 16 def run "Running workflow '#{@name}'" # Reset the current step number @current_step_num = 0 # Run the steps @steps.each do |step| # Remember the step being run @current_step = step # Increment the current step so that the first step is 1 @current_step_num += 1 # Run the step @current_step.run end "Workflow complete" end |
#unrun ⇒ Object
Undo the steps in reverse order
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/wrkflo/project.rb', line 34 def unrun "Reversing workflow '#{@name}'" # Reset the current step number @current_step_num = @steps.size # Run the steps @steps.each do |step| # Track the step being run @current_step = step # Run the step @current_step.unrun # Decrement the current step so that the last step is 1 @current_step_num -= 1 end "Workflow reversed" end |