Class: Ace::Git::Worktree::Molecules::ConfigLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/git/worktree/molecules/config_loader.rb

Overview

Configuration loader molecule

Loads and merges worktree configuration using ace-config cascade system. Handles configuration validation and provides access to merged configuration.

Examples:

Load configuration for current project

loader = ConfigLoader.new(Dir.pwd)
config = loader.load

Load with custom project root

loader = ConfigLoader.new("/path/to/project")
config = loader.load

Instance Method Summary collapse

Constructor Details

#initialize(project_root = Dir.pwd) ⇒ ConfigLoader

Initialize a new ConfigLoader

Parameters:

  • project_root (String) (defaults to: Dir.pwd)

    Project root directory



26
27
28
# File 'lib/ace/git/worktree/molecules/config_loader.rb', line 26

def initialize(project_root = Dir.pwd)
  @project_root = project_root
end

Instance Method Details

#config_exists?Boolean

Check if configuration exists

Returns:

  • (Boolean)

    true if configuration files exist



63
64
65
66
# File 'lib/ace/git/worktree/molecules/config_loader.rb', line 63

def config_exists?
  # Check for configuration files in expected locations
  config_files.each.any? { |file| File.exist?(file) }
end

#config_filesArray<String>

Get list of configuration files that would be checked

Returns:

  • (Array<String>)

    List of configuration file paths



71
72
73
74
75
76
77
# File 'lib/ace/git/worktree/molecules/config_loader.rb', line 71

def config_files
  [
    File.join(@project_root, ".ace", "git", "worktree.yml"),
    File.join(@project_root, ".ace-defaults", "git", "worktree.yml"),
    File.expand_path("~/.ace/git/worktree.yml")
  ]
end

#loadWorktreeConfig

Load and merge worktree configuration

Examples:

loader = ConfigLoader.new
config = loader.load
config.root_path # => ".ace-wt"
config.mise_trust_auto? # => true

Returns:

  • (WorktreeConfig)

    Loaded and validated configuration



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ace/git/worktree/molecules/config_loader.rb', line 39

def load
  # Load configuration using ace-config cascade
  config_hash = load_config

  # Create configuration object
  config = Models::WorktreeConfig.new(config_hash, @project_root)

  # Validate configuration
  validate_config(config)

  config
end

#load_without_validationWorktreeConfig

Load configuration without validation (for testing)

Returns:

  • (WorktreeConfig)

    Configuration without validation



55
56
57
58
# File 'lib/ace/git/worktree/molecules/config_loader.rb', line 55

def load_without_validation
  config_hash = load_config
  Models::WorktreeConfig.new(config_hash, @project_root)
end

#reset_cache!Object

Reset configuration cache



80
81
82
# File 'lib/ace/git/worktree/molecules/config_loader.rb', line 80

def reset_cache!
  @config_hash = nil
end