Class: FlossFunding::ConfigLoader

Inherits:
Object
  • Object
show all
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).

Returns:

  • (String)
File.realpath(File.join(File.dirname(__FILE__), "..", ".."))
DEFAULT_FILE =

Absolute path to the built-in default configuration YAML file.

Returns:

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

Class Method Summary collapse

Methods included from FileFinder

find_file_upwards, find_last_file_upwards, root_level=, root_level?

Class Method Details

.clear_optionsvoid

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 clear_options
  ::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.

Parameters:

  • target_dir (String)

    directory to anchor the search from

Returns:

  • (String, nil)

    absolute path to a .floss_funding.yml or nil if none found



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_configurationHash

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!.

Returns:

  • (Hash)


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.

Parameters:

  • file (String)

    absolute path to a YAML file

  • check (Boolean) (defaults to: true)

    reserved for future validations (currently unused)

Returns:

  • (Hash)

Raises:



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

Note:

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