Jake Scruggs

writes ruby/wears crazy shirts

So I've been making do with lame-o 'pre' tags for my code snippets and my blog looks, well, lame. But the various alternatives for highlighting ruby either didn't work for Blogger or smacked of effort (and you know how I feel about effort).

Well, recently I joined Obtiva and I was being all nosy looking at my new co-worker's blogs, when I found Tyler Jennings post about creating Spotlight. Take some ruby code, paste it into the text box, press a button, and you get some html which you copy and past into your blog. You'll have to include the default css in your css file the first time, but that's not too hard. Output looks like this:


 1 class Echo < ActionMailer::Base
2 def copy formatted_message, incident_id
3 users_with_echo_emails = User.find(:all,
4 :conditions => "echo_email is not NULL")
5 users_with_echo_emails.reject! {|user| !user.receive_echo?}
6 recipients_array = users_with_echo_emails.map { |user| user.echo_email }
7 recipients_array << ENV['default_echo_email'] if ENV['default_echo_email']
8
9 recipients recipients_array
10 subject "Globex pager incident #{incident_id} updated"
11 from 'noreply@globex.com'
12 body :message => formatted_message, :incident_id => incident_id
13 end
14 end



Cool huh?

So today, for something like the fifth time, I sat down in front of a TextMate installation that didn't have saving set up the way I like it: Auto save on loss of focus and when running a test (or spec). And, for the fifth time, I had to dig around the internet for the answer. So, as a public service to my future self:

Save files when focus is lost:
http://macromates.com/textmate/manual/saving_files
TextMate --> Preferences --> Advanced --> Saving

Save all files when running a test (or spec):
http://macromates.com/textmate/manual/commands
for specs:
Bundles --> Bundle Editor --> Edit Commands --> Rspec --> Run Single Example
Bundles --> Bundle Editor --> Edit Commands --> Rspec --> Run Examples
for tests:
Bundles --> Bundle Editor --> Edit Commands --> Ruby --> Run
Bundles --> Bundle Editor --> Edit Commands --> Rspec --> Run Focused Unit Test

Change the save drop down to "All Files in Project"

Hope this helps, future Jake.

Sometimes a class does too much. It's used everywhere, does everything, knows all about the nasty internals of all the other classes, and every time you change anything in the application it has to change. Or maybe you have a class that everyone loves to refactor because it's so bad. One developer changes it to be better, then another changes it to be a different kind of better, and this keeps happening without it ever getting any easier to use. There's a lot of bad reasons why a class might change all the time so I added a churn report capability to metric_fu version 0.6.0.

Now you can use metric_fu to create a report like this:

By issuing this command:

    rake metrics:churn
And use the results to find classes that might have problems. It uses 'svn log' to create this report so currently you need to be using subversion. (If anyone out there want to contribute some code to get it working with git, lemme know.) The default is to start counting changes from the start of the repository's creation. That may be too much for your project so you can change the start by adding these lines to your Rakefile:
    namespace :metrics do
CHURN_OPTIONS = { :start_date => lambda{3.months.ago} }
end
The Proc is there because '3.months.ago' only works after the Rails Environment is loaded (and Rails extends Fixnum) which I didn't want to do every time you run a rake task.

You can also change the minimum churn count (files with changes less than this number won't be included in the report) like so:
    namespace :metrics do
CHURN_OPTIONS = { :minimum_churn_count => 3 }
end
Also in this release I added the 'metrics:all_with_migrate' task because of some feedback I got that running 'metrics:all' in a cc.rb build fails if there have been migrations. So the new task migrates the test db before running all the metrics tasks.

Check out the metric_fu project home page for more information and installation instructions. Or you can jump right in by doing this in the root of your project:
script/plugin install \
http://metric-fu.rubyforge.org/svn/tags/CURRENT/metric_fu/
sudo gem install rcov
sudo gem install flog