Class: Project

Inherits:
Object
  • Object
show all
Defined in:
lib/wrkflo/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/wrkflo/project.rb', line 4

def name
  @name
end

#stepsObject

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 message
  puts "  - Step ##{@current_step_num} (#{@current_step.name}): #{message}"
end

#runObject

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
  meta_log "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

  meta_log "Workflow complete"
end

#unrunObject

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
  meta_log "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

  meta_log "Workflow reversed"
end