Class: FlossFunding::ConfigFinder Private

Inherits:
Object
  • Object
show all
Extended by:
FileFinder
Defined in:
lib/floss_funding/config_finder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class has methods related to finding a configuration path.

Constant Summary collapse

DOTFILE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

".floss_funding.yml"
XDG_CONFIG =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"config.yml"
XDG_DIRNAME =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"floss_funding"
DEFAULT_FILE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

File.join(FLOSS_FUNDING_HOME, "config", "default.yml")

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from FileFinder

find_file_upwards, find_last_file_upwards, root_level=, root_level?

Class Attribute Details

.project_rootObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the path inferred as the root of the project. No file
searches will go past this directory.



42
43
44
# File 'lib/floss_funding/config_finder.rb', line 42

def project_root
  @project_root ||= find_project_root
end

Class Method Details

.clear_caches!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Testing helper to clear internal caches



47
48
49
50
51
# File 'lib/floss_funding/config_finder.rb', line 47

def clear_caches!
  @config_path_cache = {}
  @project_root_for_cache = {}
  @project_root = nil
end

.find_config_path(target_dir) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/floss_funding/config_finder.rb', line 26

def find_config_path(target_dir)
  @config_path_cache ||= {}
  key = File.expand_path(target_dir)
  return @config_path_cache[key] if @config_path_cache.key?(key)
  path = find_project_dotfile(key) || find_user_dotfile || find_user_xdg_config || DEFAULT_FILE
  # Test-friendly fallback: when no project/user config is found (path == DEFAULT_FILE),
  # prefer a repo-root .floss_funding.yml if it exists within FLOSS_FUNDING_HOME.
  if path == DEFAULT_FILE
    repo_root_dotfile = File.join(FLOSS_FUNDING_HOME, DOTFILE)
    path = repo_root_dotfile if File.exist?(repo_root_dotfile)
  end
  @config_path_cache[key] = path
end