YAAC—yes, yet another…
, Chicago
I’ve been rolling my own app configs for awhile now. It’s been just another step in the rails newapp ritual. A chore, really. Rails templates make things a bit easier, but the logic shoudn’t untidy my lib and initializers, should it?
I know
it’s been done before,
and others will do it again, but I just had to TODO its release
when, last month, I heard Jacques Crocker blithely gloat
that
his take on AppConfig
is
better than everyone else’s
.
Au contraire, mon amie! Let me introduce my way: the way I rather like it.
Hello, App
App is yet another YAML-based, app config for Rails. App should look familiar enough. It looks for and loads from config/app.yml, and provides namespaced access:
App.config # => {"apis"=>{"flickr"=>{ ... }}
# Sugar is always sweeter:
App.config("apis", "flickr") # => App.config["apis"]["flickr"]
# Who doesn't like sugar?
App["apis", "flickr"]
# Sugar, sugar, sugar!
App.apis("flickr")
# Namespace again, if necessary, e.g., with "config/app/apis.yml":
App::Apis.flickr
So, how does App stand up against the self-proclaimed champ? Well, it’s
- ⅓ the size of AppConfig, so save yourself those last six keystrokes. It also starts you out with just one file: app.yml (no environmental waste!). (The code base? Yes, it’s slimmer, too.)
- Less magical [pej.] on the surface. Method
chaining should really only go so far, so we prefer
App.apis("twitter")to theOpenStructchoo-choo that isAppConfig.apis.twitter. - More modular (when we want it to be). If your configuration starts to outgrow itself, branch it out.
So what’s the easiest way to get started? Using this template:
You can also install App as a plugin, or maintain its gem installation yourself: just take a look at the README on GitHub.