Class: ManageIQ::Floe::Workflow::State
- Inherits:
-
Object
- Object
- ManageIQ::Floe::Workflow::State
- Includes:
- Logging
- Defined in:
- lib/manageiq/floe/workflow/state.rb
Direct Known Subclasses
ManageIQ::Floe::Workflow::States::Choice, ManageIQ::Floe::Workflow::States::Fail, ManageIQ::Floe::Workflow::States::Map, ManageIQ::Floe::Workflow::States::Parallel, ManageIQ::Floe::Workflow::States::Pass, ManageIQ::Floe::Workflow::States::Succeed, ManageIQ::Floe::Workflow::States::Task, ManageIQ::Floe::Workflow::States::Wait
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#workflow ⇒ Object
readonly
Returns the value of attribute workflow.
Class Method Summary collapse
Instance Method Summary collapse
- #context ⇒ Object
- #end? ⇒ Boolean
-
#initialize(workflow, name, payload) ⇒ State
constructor
A new instance of State.
- #run!(input) ⇒ Object
- #to_dot ⇒ Object
- #to_dot_transitions ⇒ Object
Methods included from Logging
Constructor Details
#initialize(workflow, name, payload) ⇒ State
Returns a new instance of State.
25 26 27 28 29 30 31 32 |
# File 'lib/manageiq/floe/workflow/state.rb', line 25 def initialize(workflow, name, payload) @workflow = workflow @name = name @payload = payload @end = !!payload["End"] @type = payload["Type"] @comment = payload["Comment"] end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
23 24 25 |
# File 'lib/manageiq/floe/workflow/state.rb', line 23 def comment @comment end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/manageiq/floe/workflow/state.rb', line 23 def name @name end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
23 24 25 |
# File 'lib/manageiq/floe/workflow/state.rb', line 23 def payload @payload end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
23 24 25 |
# File 'lib/manageiq/floe/workflow/state.rb', line 23 def type @type end |
#workflow ⇒ Object (readonly)
Returns the value of attribute workflow.
23 24 25 |
# File 'lib/manageiq/floe/workflow/state.rb', line 23 def workflow @workflow end |
Class Method Details
.build!(workflow, name, payload) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/manageiq/floe/workflow/state.rb', line 10 def build!(workflow, name, payload) state_type = payload["Type"] begin klass = ManageIQ::Floe::Workflow::States.const_get(state_type) rescue NameError raise ManageIQ::Floe::InvalidWorkflowError, "Invalid state type: [#{state_type}]" end klass.new(workflow, name, payload) end |
Instance Method Details
#context ⇒ Object
38 39 40 |
# File 'lib/manageiq/floe/workflow/state.rb', line 38 def context workflow.context end |
#end? ⇒ Boolean
34 35 36 |
# File 'lib/manageiq/floe/workflow/state.rb', line 34 def end? @end end |
#run!(input) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/manageiq/floe/workflow/state.rb', line 42 def run!(input) logger.info("Running state: [#{name}] with input [#{input}]") input = input_path.value(context, input) output, next_state = block_given? ? yield(input) : input next_state ||= workflow.states_by_name[payload["Next"]] unless end? output ||= input output = output_path&.value(context, output) logger.info("Running state: [#{name}] with input [#{input}]...Complete - next state: [#{next_state&.name}] output: [#{output}]") [next_state, output] end |
#to_dot ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/manageiq/floe/workflow/state.rb', line 58 def to_dot String.new.tap do |s| s << " #{name}" attributes = to_dot_attributes s << " [ #{attributes.to_a.map { |kv| kv.join("=") }.join(" ")} ]" unless attributes.empty? end end |
#to_dot_transitions ⇒ Object
71 72 73 74 |
# File 'lib/manageiq/floe/workflow/state.rb', line 71 def to_dot_transitions next_state_name = payload["Next"] unless end? Array(next_state_name && " #{name} -> #{next_state_name}") end |