diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-01 21:38:11 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-01 21:38:11 +0200 |
| commit | 197c3d39b740a69ff29afcf93bd9139cec828aa2 (patch) | |
| tree | e1e209fee3b9f649d4f5bc792b8d528a9d17e3f1 | |
| parent | 8e64fd142f90718b08fdb7d73ec58022bc18de9c (diff) | |
gracefully handle missing toml gem in config.rb
| -rw-r--r-- | lib/config.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/config.rb b/lib/config.rb index b0123e0..2a13ae0 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -1,9 +1,19 @@ -require 'toml' +begin + require 'toml' + TOML_AVAILABLE = true +rescue LoadError + TOML_AVAILABLE = false +end module RCM - # Configuration + # 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. module Config - @@config = File.exist?('config.toml') ? TOML.load_file('config.toml') : {} + @@config = if TOML_AVAILABLE && File.exist?('config.toml') + TOML.load_file('config.toml') + else + {} + end def config(key) raise "No such config key: #{key}" unless @@config.key?(key) |
