Class: Sxn::Config::ConfigDiscovery

Inherits:
Object
  • Object
show all
Defined in:
lib/sxn/config/config_discovery.rb

Overview

Handles hierarchical configuration discovery and loading

Configuration precedence (highest to lowest):

  1. Command-line flags

  2. Environment variables (SXN_*)

  3. Local project config (.sxn/config.yml)

  4. Workspace config (.sxn-workspace/config.yml)

  5. Global user config (~/.sxn/config.yml)

  6. System defaults

Constant Summary collapse

CONFIG_FILE_NAME =
"config.yml"
LOCAL_CONFIG_DIR =
".sxn"
WORKSPACE_CONFIG_DIR =
".sxn-workspace"
GLOBAL_CONFIG_DIR =
File.expand_path("~/.sxn")
ENV_PREFIX =
"SXN_"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_directory = Dir.pwd) ⇒ ConfigDiscovery

Returns a new instance of ConfigDiscovery.



26
27
28
# File 'lib/sxn/config/config_discovery.rb', line 26

def initialize(start_directory = Dir.pwd)
  @start_directory = Pathname.new(start_directory).expand_path
end

Instance Attribute Details

#start_directoryObject (readonly)

Returns the value of attribute start_directory.



24
25
26
# File 'lib/sxn/config/config_discovery.rb', line 24

def start_directory
  @start_directory
end

Instance Method Details

#discover_config(cli_options = {}) ⇒ Hash

Discover and load configuration from all sources

Parameters:

  • cli_options (Hash) (defaults to: {})

    Command-line options

Returns:

  • (Hash)

    Merged configuration



33
34
35
36
# File 'lib/sxn/config/config_discovery.rb', line 33

def discover_config(cli_options = {})
  config_sources = load_all_configs
  merge_configs(config_sources, cli_options)
end

#find_config_filesArray<String>

Find all configuration files in the hierarchy

Returns:

  • (Array<String>)

    Paths to configuration files



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sxn/config/config_discovery.rb', line 40

def find_config_files
  config_files = []

  # Local project config (.sxn/config.yml)
  local_config = find_local_config
  config_files << local_config if local_config

  # Workspace config (.sxn-workspace/config.yml)
  workspace_config = find_workspace_config
  config_files << workspace_config if workspace_config

  # Global user config (~/.sxn/config.yml)
  global_config = find_global_config
  config_files << global_config if global_config

  config_files
end