Different Ways of Installing Metric Fu

25 Sep 2008

Something I didn’t mention when I announced the re-launch of metric_fu as a gem is that now, because it’s a gem, you have more options when installing it in your project.

First option:
Vendor Everything. Lots of people are big fans of unpacking gems into the vendor directory of their Rails project (or a similar folder in a non-Rails project) so that everyone who checks out the code gets the right version of the gem. You can then require it in your Rakefile like this:

require ‘vendor/gems/jscruggs-metric_fu-0.7.6/lib/metric_fu’

However…

Second option:
Conditionally require the gem. When I announced metric_fu back in April, a lot of commentors bemoaned the fact that they would have to install something into their production code that wasn’t really necessary for production. I don’t really mind doing this as metric_fu does not modify any classes: It’s mostly just a bunch of Rake tasks (and some report building code). However, I see their point. So if you don’t want to put metric_fu into your project, you can simply make sure the gem is installed on your CruiseControl machine and then conditionally require metric_fu in a rake file like so:

begin; require ‘metric_fu’; rescue LoadError; end

So anyone who has the metric_fu gem installed on their box can run the reports, while keeping everything else pure.