I am writing my first gem and I’d like specific options to be retrieved and set by the user through a config.yml file.
Where should this file be placed within my gem file structure and how does someone modify the file when installing my gem? I’m guessing they can pass in specific options when installing the gem, and those options can be mapped to the config.yml file, but how is this possible?
Also, is the best way to retrieve the file through YAML.load_file?
I’ve watched Ryan’s railcasts on creating a gem via Bundler, but he doesn’t cover this topic.
I’m jumping on this one a little late but I’ll leave an example implementation of how I generally handle this, for future reference.
As it was mentioned, you’ll normally want to allow configuration through both files and hashes. It’s pretty easy and light to include both ways, so you should do it.
Something like this works for me in most scenarios:
An added best practice would be to have defaults for all your configuration keys(as in the example above). That way, you are giving the user ultimate freedom in how they can configure your library.