Class: SwarmCLI::ConfigLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_cli/config_loader.rb

Overview

ConfigLoader handles loading swarm configurations from both YAML and Ruby DSL files.

Supports:

  • YAML files (.yml, .yaml) - loaded via SwarmSDK.load_file
  • Ruby DSL files (.rb) - executed and expected to return a SwarmSDK::Swarm or SwarmSDK::Workflow instance

Examples:

Load YAML config

swarm = ConfigLoader.load("config.yml")

Load Ruby DSL config

swarm = ConfigLoader.load("config.rb")

Class Method Summary collapse

Class Method Details

.load(path) ⇒ SwarmSDK::Swarm, SwarmSDK::Workflow

Load a swarm configuration from file (YAML or Ruby DSL)

Detects file type by extension:

  • .yml, .yaml -> Load as YAML using SwarmSDK.load_file
  • .rb -> Execute as Ruby DSL and expect SwarmSDK::Swarm or SwarmSDK::Workflow instance

Parameters:

  • path (String, Pathname)

    Path to configuration file

Returns:

  • (SwarmSDK::Swarm, SwarmSDK::Workflow)

    Configured swarm or workflow instance

Raises:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/swarm_cli/config_loader.rb', line 27

def load(path)
  path = Pathname.new(path).expand_path

  unless path.exist?
    raise ConfigurationError, "Configuration file not found: #{path}"
  end

  case path.extname.downcase
  when ".yml", ".yaml"
    load_yaml(path)
  when ".rb"
    load_ruby_dsl(path)
  else
    raise ConfigurationError,
      "Unsupported configuration file format: #{path.extname}. " \
        "Supported formats: .yml, .yaml (YAML), .rb (Ruby DSL)"
  end
end