This release is another case of "Jeez, this is the third time I'm doing X... let's see if there's a gem for that... nopes? Let's get started!" What follows immediately after that is, of course, putting the idea on my "idea list" (a Trello board) and letting it ripe there for a few months. But eventually I came around to it and present you with: GemConfig - A nifty way to make your gem configurable
The pitch is simple: do you know these gems that can be configured (usually in an initializer) like this?
# config/initializers/awesomeness.rb Awesomeness.configure do |config| config.api_key = 'foobarbaz' config.format = :xml config.region = 'eu' end
Pretty handy, eh?
As a gem author, it first seems pretty easy to add this to your gem. Just add a
configure method, yield, add instance variables, whatever, done. Oh yeah, maybe you want to have defaults, like the
format set to
:json by default but offering the user to set it to
:xml as well? Easy. And, yes, some validations, right? So the user can't set
blueberry pie as the
format, no matter how tasty blueberry pie is. Soon enough you find you have written more code for the configuration options than for your actual gem...
GemConfig to the rescue! It takes care of all that stuff for you. Examples and usage instructions in the Github repo.