Fork me on GitHub

Posts Tagged ‘yaml’

Let’s say goodbye to YAML for configuration, shall we?

Tuesday, June 28th, 2011

I have to ask a question to my fellow Rubyists out there? Why are you still using YAML? I know why you think you like YAML. You think it’s a great way to write configuration files, but it’s really not. You know what’s a great way of writing configuration files for Ruby apps? RUBY!

I know it’s crazy, isn’t it? But why not? Why would you not want to use Ruby for configuring your applications instead of YAML?

I’m the maintainer of a pretty popular configuration tool for Ruby apps, Configatron, so I think I have a little experience in this field. I also write and maintain a lot of libraries that require configuration and I have never thought that YAML is the best way to do this.

Let’s look at an example of what a library developer has to do to load a YAML file to get configurations:

foo:
  bar
view raw config.yml This Gist brought to you by GitHub.
require 'yaml'
config = YAML.load(ERB.new(File.read('/path/to/config.yml')).result)
view raw gistfile1.rb This Gist brought to you by GitHub.

I don’t know about you, but I think that’s kind of lame. Most everybody runs their YAML files through ERB so that they can make their YAML files more ‘Ruby-ish’. Why not just use Ruby?? Here’s the same example in Ruby:

SomeLibrary.config = {:foo => :bar}
view raw config.rb This Gist brought to you by GitHub.
require '/path/to/config.rb'
view raw gistfile1.rb This Gist brought to you by GitHub.

In addition to not having to deal with all the whitespace, tabs, crazy nesting, etc… that YAML brings we get to use the full power of Ruby for our configurations! Try storing a Proc in YAML. Yeah, that’s what I thought. You can drive configurations from the database, environment variables, crazy equations, etc… the world is your oyster. All you need to do now is stop using YAML!

I’ve decided to drop YAML support in Configatron 2.9 (coming sometime this Summer) and I encourage all other library developers to do the same. It’s just not needed, or very nice for that matter. Now, if we can only get Rails to drop the database.yml file, I think we’ll be all set.

Ps. Make sure to check out my app FluxTracker.com for all your issue, project, and error tracking needs. Also check out TweetKO.com for backing up and bookmarking your favorite tweets.

Configatron 1.2.0 Released

Monday, September 8th, 2008

Thanks to Simon Menke for contributing a great patch to Configatron that will automatically ‘namespace’ your configuration settings if you use the configure_from_hash or the configure_from_yaml methods.


Both give you the same results:

If you get a chance visit Simon’s blog at: http://5xm.org/ and say hi. Thanks again Simon.

Configatron 1.1.0 Released

Thursday, September 4th, 2008

On the heels of last week’s successful release of Configatron 1.0.0 comes version 1.1.0. The big addition, feature wise, to 1.1.0 is the ability to now load configurations from a YAML file.

configatron.configure_from_yaml('/path/to/file.yml')

When reload is called on configatron any YAML files will be read back in from disk, allowing you to change your configurations and reload them.

Enjoy!