Class: Tasker::TaskBuilder

Inherits:
Object
  • Object
show all
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

ConfiguredTask

Defined Under Namespace

Classes: StepNameValidator, StepTemplateDefiner

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#configHash (readonly)



14
15
16
# File 'lib/tasker/task_builder.rb', line 14

def config
  @config
end

#handler_classClass (readonly)



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

#buildClass

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_configBoolean

Validate the configuration against the schema

Raises:



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.message}"
end