Class: Roast::Workflow::StepExecutorRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/roast/workflow/step_executor_registry.rb

Overview

Registry pattern for step executors - eliminates case statements and follows Open/Closed Principle

Defined Under Namespace

Classes: UnknownStepTypeError

Class Method Summary collapse

Class Method Details

.clear!Object

Clear all registrations (useful for testing)



43
44
45
46
47
# File 'lib/roast/workflow/step_executor_registry.rb', line 43

def clear!
  @executors.clear
  @type_matchers.clear
  StepExecutorFactory.instance_variable_set(:@defaults_registered, false)
end

.for(step, workflow_executor) ⇒ Object

Find the appropriate executor for a step

Parameters:

  • step (Object)

    The step to find an executor for

  • workflow_executor (WorkflowExecutor)

    The workflow executor instance

Returns:

  • (Object)

    An instance of the appropriate executor



32
33
34
35
36
37
38
39
40
# File 'lib/roast/workflow/step_executor_registry.rb', line 32

def for(step, workflow_executor)
  executor_class = find_executor_class(step)

  unless executor_class
    raise UnknownStepTypeError, "No executor registered for step type: #{step.class} (#{step.inspect})"
  end

  executor_class.new(workflow_executor)
end

.register(klass, executor_class) ⇒ Object

Register an executor for a specific class

Parameters:

  • klass (Class)

    The class to match

  • executor_class (Class)

    The executor class to use



17
18
19
# File 'lib/roast/workflow/step_executor_registry.rb', line 17

def register(klass, executor_class)
  @executors[klass] = executor_class
end

.register_with_matcher(matcher, executor_class) ⇒ Object

Register an executor with a custom matcher

Parameters:

  • matcher (Proc)

    A proc that returns true if the step matches

  • executor_class (Class)

    The executor class to use



24
25
26
# File 'lib/roast/workflow/step_executor_registry.rb', line 24

def register_with_matcher(matcher, executor_class)
  @type_matchers << { matcher: matcher, executor_class: executor_class }
end

.registered_executorsObject

Get all registered executors (useful for debugging)



50
51
52
# File 'lib/roast/workflow/step_executor_registry.rb', line 50

def registered_executors
  @executors.dup
end