Class: Ace::Lint::Atoms::ConfigLocator
- Inherits:
-
Object
- Object
- Ace::Lint::Atoms::ConfigLocator
- Defined in:
- lib/ace/lint/atoms/config_locator.rb
Overview
Locates configuration files for validators with precedence rules Precedence: explicit path > .ace/lint/ > native config > gem defaults Results are cached to avoid repeated filesystem I/O (thread-safe)
Constant Summary collapse
- NATIVE_CONFIGS =
Native config file names for each tool
{ standardrb: [".standard.yml"], rubocop: [".rubocop.yml"] }.freeze
- GEM_DEFAULT_CONFIGS =
Default config paths within gem defaults directory
{ standardrb: nil, # StandardRB uses its own defaults rubocop: ".rubocop.yml" }.freeze
Class Method Summary collapse
-
.locate(tool, project_root:, explicit_path: nil) ⇒ Hash
Locate config file for a validator.
-
.reset_cache! ⇒ void
Reset config cache (for testing).
-
.resolve_path(path, base) ⇒ String
Resolve a potentially relative path.
Class Method Details
.locate(tool, project_root:, explicit_path: nil) ⇒ Hash
Locate config file for a validator
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ace/lint/atoms/config_locator.rb', line 34 def self.locate(tool, project_root:, explicit_path: nil) tool_sym = tool.to_s.downcase.to_sym # 1. Explicit path takes highest precedence (not cached) if explicit_path && !explicit_path.empty? full_path = resolve_path(explicit_path, project_root) return {path: full_path, source: :explicit, exists: File.exist?(full_path)} end # Build cache key (exclude explicit_path from caching as it may vary) cache_key = "#{tool_sym}:#{project_root}" # Thread-safe cache lookup and population @cache_mutex.synchronize do # Return cached result if available return @config_cache[cache_key].dup if @config_cache.key?(cache_key) # 2. Check .ace/lint/ directory ace_config = find_ace_config(tool_sym, project_root) if ace_config @config_cache[cache_key] = ace_config return ace_config.dup end # 3. Check for native config in project root native_config = find_native_config(tool_sym, project_root) if native_config @config_cache[cache_key] = native_config return native_config.dup end # 4. Fall back to gem defaults gem_config = find_gem_default_config(tool_sym) if gem_config @config_cache[cache_key] = gem_config return gem_config.dup end result = {path: nil, source: :none, exists: false} @config_cache[cache_key] = result result end end |
.reset_cache! ⇒ void
This method returns an undefined value.
Reset config cache (for testing)
154 155 156 157 158 |
# File 'lib/ace/lint/atoms/config_locator.rb', line 154 def self.reset_cache! @cache_mutex.synchronize do @config_cache = {} end end |
.resolve_path(path, base) ⇒ String
Resolve a potentially relative path
82 83 84 85 86 |
# File 'lib/ace/lint/atoms/config_locator.rb', line 82 def self.resolve_path(path, base) return path if Pathname.new(path).absolute? File.(path, base) end |