A few months ago, I came across the Settingslogic gem. I wish I’d discovered it years ago.
Until then, I’d found myself manually handling configuration and settings via raw access to YAML files. This meant I was repeatedly writing code like the follow to handle my various needs:
All of that checking for the config file’s presence, parsing it with YAML, extracting and passing around the configuration, testing it… blah. Any individual operation is simple and straightforward, but performing all of those operations together, multiple times, is irritating and prone to errors.
Settingslogic is awesome. Now instead of the above code, I can write code like this to grab my settings:
And code like this to access them:
Since SystemConfiguration is a real object, setting it up for testing is super easy as well:
Yay! No more futzing with YAML configuration directly, passing configuration all over the place to simplify testing, worrying as much about missing files, etc. Settingslogic is straightforward and effective — and a great example of Ruby abstraction done well.
I hope you find Settingslogic as helpful as I have!