Class: Tasker::TaskHandler::ClassMethods::StepTemplateDefiner
- Inherits:
-
Object
- Object
- Tasker::TaskHandler::ClassMethods::StepTemplateDefiner
- Defined in:
- lib/tasker/task_handler/class_methods.rb
Overview
Helper class for defining step templates in task handlers
Defined Under Namespace
Classes: ClassBasedEventRegistrar, YamlEventRegistrar
Instance Attribute Summary collapse
-
#klass ⇒ Class
readonly
The class where templates are being defined.
-
#step_handler_class_map ⇒ Hash<String, String>
readonly
Mapping of step names to handler class names.
-
#step_handler_config_map ⇒ Hash<String, Object>
readonly
Mapping of step names to handler configs.
-
#step_templates ⇒ Array<Tasker::Types::StepTemplate>
readonly
The defined step templates.
Instance Method Summary collapse
-
#define(**kwargs) ⇒ void
Define a new step template.
-
#initialize(klass) ⇒ StepTemplateDefiner
constructor
Create a new step template definer.
-
#register_class_map ⇒ void
Register the mapping of step names to handler classes and configs.
Constructor Details
#initialize(klass) ⇒ StepTemplateDefiner
Create a new step template definer
33 34 35 36 37 38 |
# File 'lib/tasker/task_handler/class_methods.rb', line 33 def initialize(klass) @klass = klass @step_templates = [] @step_handler_class_map = {} @step_handler_config_map = {} end |
Instance Attribute Details
#klass ⇒ Class (readonly)
Returns The class where templates are being defined.
21 22 23 |
# File 'lib/tasker/task_handler/class_methods.rb', line 21 def klass @klass end |
#step_handler_class_map ⇒ Hash<String, String> (readonly)
Returns Mapping of step names to handler class names.
24 25 26 |
# File 'lib/tasker/task_handler/class_methods.rb', line 24 def step_handler_class_map @step_handler_class_map end |
#step_handler_config_map ⇒ Hash<String, Object> (readonly)
Returns Mapping of step names to handler configs.
27 28 29 |
# File 'lib/tasker/task_handler/class_methods.rb', line 27 def step_handler_config_map @step_handler_config_map end |
#step_templates ⇒ Array<Tasker::Types::StepTemplate> (readonly)
Returns The defined step templates.
18 19 20 |
# File 'lib/tasker/task_handler/class_methods.rb', line 18 def step_templates @step_templates end |
Instance Method Details
#define(**kwargs) ⇒ void
This method returns an undefined value.
Define a new step template
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/tasker/task_handler/class_methods.rb', line 55 def define(**kwargs) dependent_system = kwargs.fetch(:dependent_system, Tasker::Constants::UNKNOWN) name = kwargs.fetch(:name) handler_class = kwargs.fetch(:handler_class) description = kwargs.fetch(:description, name) default_retryable = kwargs.fetch(:default_retryable, true) default_retry_limit = kwargs.fetch(:default_retry_limit, 3) skippable = kwargs.fetch(:skippable, false) depends_on_step = kwargs.fetch(:depends_on_step, nil) depends_on_steps = kwargs.fetch(:depends_on_steps, []) handler_config = kwargs.fetch(:handler_config, nil) custom_events = kwargs.fetch(:custom_events, []) # Register custom events (both YAML-based and class-based) when step template is defined register_custom_events_for_handler(custom_events, handler_class) @step_templates << Tasker::Types::StepTemplate.new( dependent_system: dependent_system, name: name, description: description, default_retryable: default_retryable, default_retry_limit: default_retry_limit, skippable: skippable, handler_class: handler_class, depends_on_step: depends_on_step, depends_on_steps: depends_on_steps, handler_config: handler_config, custom_events: custom_events ) end |
#register_class_map ⇒ void
This method returns an undefined value.
Register the mapping of step names to handler classes and configs
89 90 91 92 93 94 |
# File 'lib/tasker/task_handler/class_methods.rb', line 89 def register_class_map @step_templates.each do |template| @step_handler_class_map[template.name] = template.handler_class.to_s @step_handler_config_map[template.name] = template.handler_config end end |