Module: Legion::Gaia::Workflow::ClassMethods

Defined in:
lib/legion/gaia/workflow.rb

Instance Method Summary collapse

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.

Parameters:

  • name (Symbol, nil) (defaults to: nil)

    workflow name; defaults to first registered

  • metadata (Hash) (defaults to: {})

Returns:

Raises:

  • (ArgumentError)


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.

Parameters:

  • name (Symbol, String)

Yields:

  • (definition)

    DSL block receives the new Definition object

Returns:



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.

Returns:



81
82
83
# File 'lib/legion/gaia/workflow.rb', line 81

def workflow_definition(name)
  @workflow_definitions&.[](name.to_sym)
end

#workflow_definitionsHash{Symbol => Definition}

Returns all definitions registered on this class.

Returns:



87
88
89
# File 'lib/legion/gaia/workflow.rb', line 87

def workflow_definitions
  @workflow_definitions || {}
end