Class: Roast::Workflow::Configuration
- Inherits:
-
Object
- Object
- Roast::Workflow::Configuration
- Defined in:
- lib/roast/workflow/configuration.rb
Overview
Encapsulates workflow configuration data and provides structured access to the configuration settings
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
-
#config_hash ⇒ Object
readonly
Returns the value of attribute config_hash.
-
#function_configs ⇒ Object
readonly
Returns the value of attribute function_configs.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#target ⇒ Object
Returns the value of attribute target.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
-
#workflow_path ⇒ Object
readonly
Returns the value of attribute workflow_path.
Instance Method Summary collapse
- #basename ⇒ Object
- #context_path ⇒ Object
-
#find_step_index(steps_array = nil, target_step = nil) ⇒ Integer?
Find the index of a step in the workflow steps array.
-
#function_config(function_name) ⇒ Hash
Get configuration for a specific function.
- #get_step_config(step_name) ⇒ Object
- #has_target? ⇒ Boolean
-
#initialize(workflow_path, options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
-
#parse_functions ⇒ Object
Parse function-specific configurations.
-
#parse_tools ⇒ Object
Returns an array of all tool class names.
Constructor Details
#initialize(workflow_path, options = {}) ⇒ Configuration
Returns a new instance of Configuration.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/roast/workflow/configuration.rb', line 14 def initialize(workflow_path, = {}) @workflow_path = workflow_path @config_hash = YAML.load_file(workflow_path) # Extract key configuration values @name = @config_hash["name"] || File.basename(workflow_path, ".yml") @steps = @config_hash["steps"] || [] # Process tools configuration parse_tools # Process function-specific configurations parse_functions # Read the target parameter @target = [:target] || @config_hash["target"] # Process the target command if it's a shell command @target = process_target(@target) if has_target? # Create the appropriate resource object for the target if defined?(Roast::Resources) @resource = if has_target? Roast::Resources.for(@target) else Roast::Resources::NoneResource.new(nil) end end # Process API token if provided if @config_hash["api_token"] @api_token = process_shell_command(@config_hash["api_token"]) end # Extract default model if provided @model = @config_hash["model"] end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
11 12 13 |
# File 'lib/roast/workflow/configuration.rb', line 11 def api_token @api_token end |
#config_hash ⇒ Object (readonly)
Returns the value of attribute config_hash.
11 12 13 |
# File 'lib/roast/workflow/configuration.rb', line 11 def config_hash @config_hash end |
#function_configs ⇒ Object (readonly)
Returns the value of attribute function_configs.
11 12 13 |
# File 'lib/roast/workflow/configuration.rb', line 11 def function_configs @function_configs end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
11 12 13 |
# File 'lib/roast/workflow/configuration.rb', line 11 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/roast/workflow/configuration.rb', line 11 def name @name end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
11 12 13 |
# File 'lib/roast/workflow/configuration.rb', line 11 def resource @resource end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
11 12 13 |
# File 'lib/roast/workflow/configuration.rb', line 11 def steps @steps end |
#target ⇒ Object
Returns the value of attribute target.
12 13 14 |
# File 'lib/roast/workflow/configuration.rb', line 12 def target @target end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
11 12 13 |
# File 'lib/roast/workflow/configuration.rb', line 11 def tools @tools end |
#workflow_path ⇒ Object (readonly)
Returns the value of attribute workflow_path.
11 12 13 |
# File 'lib/roast/workflow/configuration.rb', line 11 def workflow_path @workflow_path end |
Instance Method Details
#basename ⇒ Object
56 57 58 |
# File 'lib/roast/workflow/configuration.rb', line 56 def basename @basename ||= File.basename(workflow_path, ".yml") end |
#context_path ⇒ Object
52 53 54 |
# File 'lib/roast/workflow/configuration.rb', line 52 def context_path @context_path ||= File.dirname(workflow_path) end |
#find_step_index(steps_array = nil, target_step = nil) ⇒ Integer?
Find the index of a step in the workflow steps array
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/roast/workflow/configuration.rb', line 72 def find_step_index(steps_array = nil, target_step = nil) # Handle different call patterns for backward compatibility if steps_array.is_a?(String) && target_step.nil? target_step = steps_array steps_array = steps elsif steps_array.is_a?(Array) && target_step.is_a?(String) # This is the normal case - steps_array and target_step are provided else # Default to self.steps if just the target_step is provided steps_array = steps end # First, try using the new more detailed search steps_array.each_with_index do |step, index| case step when Hash # Could be {name: command} or {name: {substeps}} step_key = step.keys.first return index if step_key == target_step when Array # This is a parallel step container, search inside it found = step.any? do |substep| case substep when Hash substep.keys.first == target_step when String substep == target_step else false end end return index if found when String return index if step == target_step end end # Fall back to the original method using extract_step_name steps_array.each_with_index do |step, index| step_name = extract_step_name(step) if step_name.is_a?(Array) # For arrays (parallel steps), check if target is in the array return index if step_name.flatten.include?(target_step) elsif step_name == target_step return index end end nil end |
#function_config(function_name) ⇒ Hash
Get configuration for a specific function
137 138 139 |
# File 'lib/roast/workflow/configuration.rb', line 137 def function_config(function_name) @function_configs[function_name.to_s] || {} end |
#get_step_config(step_name) ⇒ Object
64 65 66 |
# File 'lib/roast/workflow/configuration.rb', line 64 def get_step_config(step_name) @config_hash[step_name] || {} end |
#has_target? ⇒ Boolean
60 61 62 |
# File 'lib/roast/workflow/configuration.rb', line 60 def has_target? !target.nil? && !target.empty? end |
#parse_functions ⇒ Object
Parse function-specific configurations
130 131 132 |
# File 'lib/roast/workflow/configuration.rb', line 130 def parse_functions @function_configs = @config_hash["functions"] || {} end |
#parse_tools ⇒ Object
Returns an array of all tool class names
124 125 126 127 |
# File 'lib/roast/workflow/configuration.rb', line 124 def parse_tools # Only support array format: ["Roast::Tools::Grep", "Roast::Tools::ReadFile"] @tools = @config_hash["tools"] || [] end |