Module: CMDx::Workflow::ClassMethods

Defined in:
lib/cmdx/workflow.rb

Instance Method Summary collapse

Instance Method Details

#method_added(method_name) ⇒ Object

Prevents redefinition of the work method to maintain workflow integrity.

Examples:

class MyWorkflow
  include CMDx::Workflow
  # This would raise an error:
  # def work; end
end

Parameters:

  • method_name (Symbol)

    The name of the method being added

Raises:

  • (RuntimeError)

    If attempting to redefine the work method



25
26
27
28
29
# File 'lib/cmdx/workflow.rb', line 25

def method_added(method_name)
  raise "cannot redefine #{name}##{method_name} method" if method_name == :work

  super
end

#pipelineArray<ExecutionGroup>

Returns the collection of execution groups for this workflow.

Examples:

class MyWorkflow
  include CMDx::Workflow
  task Task1
  task Task2
  puts pipeline.size # => 2
end

Returns:



44
45
46
# File 'lib/cmdx/workflow.rb', line 44

def pipeline
  @pipeline ||= []
end

#tasks(*tasks, **options) ⇒ Object Also known as: task

Adds multiple tasks to the workflow with optional configuration.

Examples:

class MyWorkflow
  include CMDx::Workflow
  tasks ValidateTask, ProcessTask, NotifyTask, breakpoints: [:failure, :halt]
end

Parameters:

  • tasks (Array<Class>)

    Array of task classes to add

  • options (Hash)

    Configuration options for the task execution

Options Hash (**options):

  • :breakpoints (Hash)

    Breakpoints that trigger workflow interruption

  • :conditions (Hash)

    Conditional logic for task execution

Raises:

  • (TypeError)

    If any task is not a CMDx::Task subclass



64
65
66
67
68
69
70
71
72
73
# File 'lib/cmdx/workflow.rb', line 64

def tasks(*tasks, **options)
  pipeline << ExecutionGroup.new(
    tasks.map do |task|
      next task if task.is_a?(Class) && (task <= Task)

      raise TypeError, "must be a CMDx::Task"
    end,
    options
  )
end