From 197c3d39b740a69ff29afcf93bd9139cec828aa2 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 1 Mar 2026 21:38:11 +0200 Subject: gracefully handle missing toml gem in config.rb --- lib/config.rb | 16 +++++++++++++--- 1 file 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) -- cgit v1.2.3