Class: Rockflow::Step
- Inherits:
-
Object
- Object
- Rockflow::Step
- Defined in:
- lib/rockflow/step.rb
Instance Attribute Summary collapse
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#flow ⇒ Object
Returns the value of attribute flow.
-
#params ⇒ Object
Returns the value of attribute params.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #add_after_dependencies(deps = []) ⇒ Object
- #add_payload(key, value) ⇒ Object
- #after_dependencies_finished? ⇒ Boolean
- #execute_post_conditions ⇒ Object
- #execute_pre_conditions ⇒ Object
- #fail! ⇒ Object
- #failed? ⇒ Boolean
- #finish! ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(flow, opts = {}) ⇒ Step
constructor
A new instance of Step.
- #it_up ⇒ Object
- #payload ⇒ Object
- #select_conditions(pre_or_post) ⇒ Object
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
#conditions ⇒ Object
Returns the value of attribute conditions.
3 4 5 |
# File 'lib/rockflow/step.rb', line 3 def conditions @conditions end |
#errors ⇒ Object
Returns the value of attribute errors.
3 4 5 |
# File 'lib/rockflow/step.rb', line 3 def errors @errors end |
#flow ⇒ Object
Returns the value of attribute flow.
3 4 5 |
# File 'lib/rockflow/step.rb', line 3 def flow @flow end |
#params ⇒ Object
Returns the value of attribute params.
3 4 5 |
# File 'lib/rockflow/step.rb', line 3 def params @params end |
#status ⇒ Object
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
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_conditions ⇒ Object
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_conditions ⇒ Object
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
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
26 27 28 |
# File 'lib/rockflow/step.rb', line 26 def finished? @status == :finished end |
#it_up ⇒ Object
15 16 |
# File 'lib/rockflow/step.rb', line 15 def it_up end |
#payload ⇒ Object
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 |