Class: Rockflow::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/rockflow/step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flow, opts = {}) ⇒ Step

Returns a new instance of Step.



5
6
7
8
9
10
11
12
13
# File 'lib/rockflow/step.rb', line 5

def initialize(flow, opts = {})
  @flow = flow
  @after_dependencies = []
  @errors = []
  @params = opts[:params]
  @status = :not_started
  @conditions = opts[:conditions]
  add_after_dependencies(opts[:after])
end

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions.



3
4
5
# File 'lib/rockflow/step.rb', line 3

def conditions
  @conditions
end

#errorsObject

Returns the value of attribute errors.



3
4
5
# File 'lib/rockflow/step.rb', line 3

def errors
  @errors
end

#flowObject

Returns the value of attribute flow.



3
4
5
# File 'lib/rockflow/step.rb', line 3

def flow
  @flow
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/rockflow/step.rb', line 3

def params
  @params
end

#statusObject

Returns the value of attribute status.



3
4
5
# File 'lib/rockflow/step.rb', line 3

def status
  @status
end

Instance Method Details

#add_after_dependencies(deps = []) ⇒ Object



42
43
44
45
46
# File 'lib/rockflow/step.rb', line 42

def add_after_dependencies(deps = [])
  [deps].flatten.each do |dep|
    @after_dependencies << dep
  end
end

#add_payload(key, value) ⇒ Object



38
39
40
# File 'lib/rockflow/step.rb', line 38

def add_payload(key, value)
  @flow.payload[key] = value
end

#after_dependencies_finished?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
# File 'lib/rockflow/step.rb', line 48

def after_dependencies_finished?
  @after_dependencies.inject(true) do |result, elem|
    dependent_steps_running = !(@flow.steps.select do |step|
      step.class == elem && !step.finished?
    end.any?)
    result = result && dependent_steps_running
    result
  end
end

#execute_post_conditionsObject



72
73
74
75
76
# File 'lib/rockflow/step.rb', line 72

def execute_post_conditions
  select_conditions(:post).each do |cond|
    exec_condition(cond, ::Rockflow::Errors::PostCondition)
  end
end

#execute_pre_conditionsObject



66
67
68
69
70
# File 'lib/rockflow/step.rb', line 66

def execute_pre_conditions
  select_conditions(:pre).each do |cond|
    exec_condition(cond, ::Rockflow::Errors::PreCondition)
  end
end

#fail!Object



30
31
32
# File 'lib/rockflow/step.rb', line 30

def fail!
  @status = :failed
end

#failed?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/rockflow/step.rb', line 34

def failed?
  @status == :failed
end

#finish!Object



22
23
24
# File 'lib/rockflow/step.rb', line 22

def finish!
  @status = :finished
end

#finished?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/rockflow/step.rb', line 26

def finished?
  @status == :finished
end

#it_upObject



15
16
# File 'lib/rockflow/step.rb', line 15

def it_up
end

#payloadObject



18
19
20
# File 'lib/rockflow/step.rb', line 18

def payload
  @flow.payload
end

#select_conditions(pre_or_post) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/rockflow/step.rb', line 58

def select_conditions(pre_or_post)
  conditions.select do |cond|
    cond[pre_or_post.to_sym]
  end.map do |cond|
    cond[pre_or_post.to_sym]
  end rescue []
end