Update: This article is obsolete. Gemcutter should take first place in your gem sources. This way there is no reason to use :source option at all.
Now is the worst time for duplication in gem configs with all the changes going on. GitHub is not a gem host anymore. Soon RubyForge may follow the same path.
with_options provides a perfect way to minimize this duplication. I personally forgot it even existed until now. Watch how this mess:
config.gem "authlogic", :source => "http://gemcutter.org"
config.gem "compass", :source => "http://gemcutter.org"
config.gem "will_paginate", :source => "http://gemcutter.org"
config.gem "inherited_resources", :source => "http://gemcutter.org"
config.gem "haml", :source => "http://gemcutter.org"
becomes dry
c.gem "settingslogic"
c.gem "authlogic"
c.gem "compass"
c.gem "will_paginate"
c.gem "inherited_resources"
c.gem "haml"
end
Update: Forgot to mention that you need to require "active_support" in order for this to work in tests, etc. Thanks daeltar in comments.
You are missing require ‘active_support’
Good point, thanks. : )
There are solid design reasons why activesupport ISN’T loaded at this point. I’d recommend that anybody using this trick be on the lookout for weird behavior that might be caused by early loading.
There are more reasons not to use this. Posted an “obsolete” update.
[...] Drier gem configs – nice, though we’ve recently dropped source except when explicitly needing a github gem that hadn’t moved to gemcutter yet. [...]