Class: Tasker::TaskBuilder
- Inherits:
-
Object
- Object
- Tasker::TaskBuilder
- Defined in:
- lib/tasker/task_builder.rb
Overview
Builds task handler classes from configuration
TaskBuilder provides a way to dynamically create task handler classes from configuration defined in YAML or passed programmatically. It handles validation, step definition, and handler registration.
Direct Known Subclasses
Defined Under Namespace
Classes: StepNameValidator, StepTemplateDefiner
Instance Attribute Summary collapse
-
#config ⇒ Hash
readonly
The configuration used to build the task handler.
-
#handler_class ⇒ Class
readonly
The generated task handler class.
Class Method Summary collapse
-
.from_yaml(yaml_path) ⇒ TaskBuilder
Create a new TaskBuilder from a YAML file.
Instance Method Summary collapse
-
#build ⇒ Class
Build the task handler class from the configuration.
-
#initialize(config: {}) ⇒ TaskBuilder
constructor
Create a new TaskBuilder with the given configuration.
-
#validate_config ⇒ Boolean
Validate the configuration against the schema.
Constructor Details
#initialize(config: {}) ⇒ TaskBuilder
Create a new TaskBuilder with the given configuration
23 24 25 26 27 |
# File 'lib/tasker/task_builder.rb', line 23 def initialize(config: {}) @config = deep_merge_configs(config) validate_config build end |
Instance Attribute Details
#config ⇒ Hash (readonly)
Returns The configuration used to build the task handler.
14 15 16 |
# File 'lib/tasker/task_builder.rb', line 14 def config @config end |
#handler_class ⇒ Class (readonly)
Returns The generated task handler class.
17 18 19 |
# File 'lib/tasker/task_builder.rb', line 17 def handler_class @handler_class end |
Class Method Details
.from_yaml(yaml_path) ⇒ TaskBuilder
Create a new TaskBuilder from a YAML file
33 34 35 36 |
# File 'lib/tasker/task_builder.rb', line 33 def self.from_yaml(yaml_path) cfg = YAML.load_file(yaml_path) new(config: cfg) end |
Instance Method Details
#build ⇒ Class
Build the task handler class from the configuration
41 42 43 |
# File 'lib/tasker/task_builder.rb', line 41 def build build_and_register_handler end |
#validate_config ⇒ Boolean
Validate the configuration against the schema
49 50 51 52 53 54 55 |
# File 'lib/tasker/task_builder.rb', line 49 def validate_config JSON::Validator.validate!(Tasker::Constants::YAML_SCHEMA, @config) validate_step_names true rescue JSON::Schema::ValidationError => e raise InvalidTaskHandlerConfig, "Invalid task handler configuration: #{e.}" end |