Note to Self: Roll Your Own YAML Config Files

by Zach Briggs

Adding your own config files to a Rails project should be easy but there isn't much clear guidance on doing it well. Here is how to parse the sweet, sweet YAML without surprising the person inheriting your code. We put this in initializers because it is the obvious place and because the deserialization only happens once, on Rails boot.

config/initializers/my_sweet_class.rb

Keep in mind that you'll need a bit of code in the spec helper to set those variables when testing in isolation. Please do not set defaults when the configuration is for a database-y operation. Fail loudly and proudly when the setup isn't performed.