Class: FlossFunding::ConfigLoader
- Inherits:
-
Object
- Object
- FlossFunding::ConfigLoader
- Extended by:
- FileFinder
- Defined in:
- lib/floss_funding/config_loader.rb
Overview
Lightweight configuration loader facade adapted from RuboCop but trimmed
down for FlossFunding’s needs. Provides only the minimal API we require
to locate and load YAML configuration files for libraries using the
FlossFunding integration.
Constant Summary collapse
- FLOSS_FUNDING_HOME =
Absolute path to the root of the floss_funding project (the gem itself).
File.realpath(File.join(File.dirname(__FILE__), "..", ".."))
- DEFAULT_FILE =
Absolute path to the built-in default configuration YAML file.
File.join(FLOSS_FUNDING_HOME, "config", "default.yml")
Class Method Summary collapse
-
.clear_options ⇒ void
Clear any memoized or process-level options in FileFinder that may affect config discovery between runs (primarily a testing helper).
-
.configuration_file_for(target_dir) ⇒ String?
Returns the path to the applicable config file for target_dir.
-
.default_configuration ⇒ Hash
Returns the default configuration hash loaded from default.yml.
-
.load_file(file, check: true) ⇒ Hash
Loads a YAML file and returns a Hash.
-
.reset_caches! ⇒ void
Testing hook to clear internal caches.
Methods included from FileFinder
find_file_upwards, find_last_file_upwards, root_level=, root_level?
Class Method Details
.clear_options ⇒ void
This method returns an undefined value.
Clear any memoized or process-level options in FileFinder that may
affect config discovery between runs (primarily a testing helper).
38 39 40 |
# File 'lib/floss_funding/config_loader.rb', line 38 def ::FlossFunding::FileFinder.root_level = nil end |
.configuration_file_for(target_dir) ⇒ String?
Returns the path to the applicable config file for target_dir.
Delegates to ConfigFinder which performs the upward search.
47 48 49 |
# File 'lib/floss_funding/config_loader.rb', line 47 def configuration_file_for(target_dir) ::FlossFunding::ConfigFinder.find_config_path(target_dir) end |
.default_configuration ⇒ Hash
Returns the default configuration hash loaded from default.yml.
Values are raw as provided in YAML; downstream code will normalize
them as needed (e.g., wrapping scalars into arrays).
Memoized for the lifetime of the process; tests may clear via reset_caches!.
72 73 74 |
# File 'lib/floss_funding/config_loader.rb', line 72 def default_configuration @default_configuration ||= load_file(DEFAULT_FILE).freeze end |
.load_file(file, check: true) ⇒ Hash
Loads a YAML file and returns a Hash. When the file is unreadable or
contains invalid YAML, returns an empty Hash. When the file is missing,
raises ConfigNotFoundError.
59 60 61 62 63 64 65 |
# File 'lib/floss_funding/config_loader.rb', line 59 def load_file(file, check: true) YAML.safe_load(File.read(file)) || {} rescue Errno::ENOENT raise ConfigNotFoundError, "Configuration file not found: #{file}" rescue StandardError {} end |
.reset_caches! ⇒ void
Test shim: used by specs/benchmarks; no internal usage as of 2025-08-13.
This method returns an undefined value.
Testing hook to clear internal caches
79 80 81 |
# File 'lib/floss_funding/config_loader.rb', line 79 def reset_caches! @default_configuration = nil end |