Class: Roast::Workflow::StepExecutorRegistry
- Inherits:
-
Object
- Object
- Roast::Workflow::StepExecutorRegistry
- 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
-
.clear! ⇒ Object
Clear all registrations (useful for testing).
-
.for(step, workflow_executor) ⇒ Object
Find the appropriate executor for a step.
-
.register(klass, executor_class) ⇒ Object
Register an executor for a specific class.
-
.register_with_matcher(matcher, executor_class) ⇒ Object
Register an executor with a custom matcher.
-
.registered_executors ⇒ Object
Get all registered executors (useful for debugging).
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
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
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
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_executors ⇒ Object
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 |