Tech Talk

Bytefull of Tech Talk (http://tech.bytefull.com)

Handy Rake tasks for your TODOs

Here’s a rake task to list TODOs in all *.rb files under a Rails application’s app directory, and another to open them in VIM (or your preferred editor):

require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
 
namespace :todo do
  desc 'List TODOs in all .rb files under app/'
  task(:list) do
      FileList["app/**/*.rb"].egrep(/TODO/)
  end
 
  desc 'Edit all TODOs in VIM' # or your favorite editor
  task(:edit) do
      # jump to the first TODO in the first file
      cmd = 'vim +/TODO/' 
 
      filelist = []
      FileList["app/**/*.rb"].egrep(/TODO/) {|fn,cnt,line| filelist << fn}
 
      # will fork a new process and exit, if you're using gvim
      system("#{cmd} #{filelist.sort.join(' ')}") 
  end
end

Put the above code in a .task file under lib/tasks/, and invoke them with rake todo:list, and rake todo:edit respectively.

Sample Output of rake todo:list:

app/models/xxxx_transaction.rb:13: # TODO: rewrite this ...
app/controllers/membership_controller.rb:98:  # TODO: raise an exception
July 18th, 2007 | ahsan | Code, Rails

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.