Module: Legion::Gaia::Workflow::ClassMethods
- Defined in:
- lib/legion/gaia/workflow.rb
Instance Method Summary collapse
-
#create_workflow(name: nil, metadata: {}) ⇒ Instance
Create an Instance for the named workflow.
-
#workflow(name) {|definition| ... } ⇒ Definition
Define a named workflow on this class.
-
#workflow_definition(name) ⇒ Definition?
Look up a Definition by name.
-
#workflow_definitions ⇒ Hash{Symbol => Definition}
Returns all definitions registered on this class.
Instance Method Details
#create_workflow(name: nil, metadata: {}) ⇒ Instance
Create an Instance for the named workflow. Uses the first (and usually only) definition if name is omitted.
97 98 99 100 101 102 |
# File 'lib/legion/gaia/workflow.rb', line 97 def create_workflow(name: nil, metadata: {}) target = name ? workflow_definition(name) : workflow_definitions.values.first raise ArgumentError, "No workflow definition found for #{name.inspect}" unless target Instance.new(definition: target, metadata: ) end |
#workflow(name) {|definition| ... } ⇒ Definition
Define a named workflow on this class. Successive calls with the same name replace the previous definition.
71 72 73 74 75 76 77 |
# File 'lib/legion/gaia/workflow.rb', line 71 def workflow(name, &block) @workflow_definitions ||= {} defn = Definition.new(name.to_sym) block&.call(defn) @workflow_definitions[name.to_sym] = defn defn end |
#workflow_definition(name) ⇒ Definition?
Look up a Definition by name.
81 82 83 |
# File 'lib/legion/gaia/workflow.rb', line 81 def workflow_definition(name) @workflow_definitions&.[](name.to_sym) end |
#workflow_definitions ⇒ Hash{Symbol => Definition}
Returns all definitions registered on this class.
87 88 89 |
# File 'lib/legion/gaia/workflow.rb', line 87 def workflow_definitions @workflow_definitions || {} end |