Class: Ace::Support::Config::Molecules::ProjectConfigScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/config/molecules/project_config_scanner.rb

Overview

Scan project tree downward to find all config folders (.ace)

Complements ConfigFinder’s upward traversal by scanning the entire project tree for all config directories. Useful for monorepos where multiple packages have distributed configurations.

Examples:

Scan all .ace folders

scanner = ProjectConfigScanner.new(project_root: Dir.pwd)
scanner.scan
# => { "." => ["git/commit.yml"], "ace-bundle" => ["git/commit.yml"] }

Find specific config across project

scanner.find_all(namespace: "git", filename: "commit")
# => { "." => "/project/.ace/git/commit.yml" }

Constant Summary collapse

SKIP_DIRS =

Directories to skip during traversal

%w[.git .cache vendor node_modules tmp coverage
.bundle _legacy .ace-local .ace-tasks .ace-taskflow].freeze

Instance Method Summary collapse

Constructor Details

#initialize(project_root: nil, config_dir: ".ace") ⇒ ProjectConfigScanner

Returns a new instance of ProjectConfigScanner.

Parameters:

  • project_root (String, nil) (defaults to: nil)

    Root directory to scan (default: Dir.pwd)

  • config_dir (String) (defaults to: ".ace")

    Config folder name (default: “.ace”)



28
29
30
31
# File 'lib/ace/support/config/molecules/project_config_scanner.rb', line 28

def initialize(project_root: nil, config_dir: ".ace")
  @project_root = File.expand_path(project_root || Dir.pwd)
  @config_dir = config_dir
end

Instance Method Details

#find_all(namespace:, filename:) ⇒ Hash{String => String}

Find all instances of a specific config file across the project

Parameters:

  • namespace (String)

    Config namespace (e.g., “git”)

  • filename (String)

    Config filename without extension (e.g., “commit”)

Returns:

  • (Hash{String => String})

    Map of relative location => absolute file path



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ace/support/config/molecules/project_config_scanner.rb', line 47

def find_all(namespace:, filename:)
  result = {}

  scan.each do |location, files|
    yml_target = "#{namespace}/#{filename}.yml"
    yaml_target = "#{namespace}/#{filename}.yaml"

    matched = if files.include?(yml_target)
      yml_target
    elsif files.include?(yaml_target)
      yaml_target
    end

    next unless matched

    ace_dir = location_to_ace_dir(location)
    result[location] = File.join(ace_dir, matched)
  end

  result
end

#scanHash{String => Array<String>}

Scan project tree for all config folders and their files

Results are memoized so multiple calls reuse one traversal.

Returns:

  • (Hash{String => Array<String>})

    Map of relative location => config file list



38
39
40
# File 'lib/ace/support/config/molecules/project_config_scanner.rb', line 38

def scan
  @scan_result ||= perform_scan
end