diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-02 08:34:35 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-02 08:34:35 +0200 |
| commit | c1275b2c29ba755d88d7c0253e0c32e820389107 (patch) | |
| tree | 8713a342f84ab8a432f781573dd1a6e7178cd51d /lib/config.rb | |
| parent | 7c439bef61b90e6744ac971a999262a0eeb76750 (diff) | |
| parent | 5b8ce0b75271af6b4799800178ab3039d97c47b7 (diff) | |
Merge branch 'develop'
Includes security fixes, bug fixes, and code quality refactors:
- Fix command injection in DNFPackageManager (system() multi-arg form)
- Fix backup_resursively! typo (latent NoMethodError)
- Add error handling to DNFPackageManager (CommandFailed + run_dnf!)
- Split file.rb monolith into per-class files
- Extract DryRun concern (SRP), narrow BasicFile interface (ISP)
- Extract register_keyword DSL helper (DRY)
- Replace ObjectSpace scan with inherited-hook class registry
- Defer Options.parse! and Config.load! to application entry point
- Add Justfiles to all example directories
Diffstat (limited to 'lib/config.rb')
| -rw-r--r-- | lib/config.rb | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/config.rb b/lib/config.rb index 2a13ae0..fa43c4f 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -8,12 +8,23 @@ end module RCM # Configuration — config.toml is optional. If the toml gem is not installed # or no config.toml exists, config() will raise a helpful error when called. + # + # Config is not loaded at module load time. Call Config.load! once at the + # application entry point (e.g. from configure) before calling config(). + # Tests that don't use config() don't need config.toml at all. module Config - @@config = if TOML_AVAILABLE && File.exist?('config.toml') - TOML.load_file('config.toml') - else - {} - end + @@config = {} + + # Load (or reload) config.toml from the current working directory. + # Falls back to an empty hash when the toml gem is unavailable or the + # file does not exist, so callers that never invoke config() are unaffected. + def self.load! + @@config = if TOML_AVAILABLE && ::File.exist?('config.toml') + TOML.load_file('config.toml') + else + {} + end + end def config(key) raise "No such config key: #{key}" unless @@config.key?(key) |
