What's New in Edge Rails: Source Code Annotations

Posted by ryan
at 2:54 PM on Monday, February 26, 2007

No, not the heavyweight annotations that you see in Java or C# – these are just a way to denote the todos and other mental reminders we often litter in our code comments:

1
2
3
4
5
6
7
8
9
class ContactsController < ApplicationController
  
  # TODO: factor out model verification to a filter
  # OPTIMIZE: optimize this
  # FIXME: it's broken
  def index
    ...
  end
end

With this new rake task we can now spit out a list of items we’ve annotated:

1
2
3
4
5
rake notes
app/controllers/contacts_controller.rb:
  * [ 3] [TODO] factor out model verification to a filter
  * [ 4] [OPTIMIZE] optimize this
  * [ 5] [FIXME] it's broken

You can also only list the annotations of a particular kind with rake notes:todo, rake notes:optimize and rake notes:fixme.

Update: JD has this tip to get this rake task installed in your non-edge Rails app. Thanks, JD!
1
2
cd lib/tasks && \
  wget http://dev.rubyonrails.org/export/7553/trunk/railties/lib/tasks/annotations.rake
Update: You can now search for a custom annotation by passing in the annotation text as follows:

rake notes:custom ANNOTATION=MYTAG

tags: rubyonrails, rails

Comments

Leave a response

  1. John TopleyFebruary 26, 2007 @ 04:24 PM

    Someone’s been very busy lately! Lots going on in the world of Edge Rails.

  2. Christian RomneyFebruary 26, 2007 @ 04:41 PM

    I love how lightweight and useful this is!

  3. MaxFebruary 27, 2007 @ 07:30 AM

    Nice, very nice… I am used to this stuff from VisualStudio and love this feature. Now it will be available to rails… so nice ;)

  4. Daniel SchierbeckFebruary 27, 2007 @ 03:33 PM

    Could this perhaps be extracted from rails? I’d really like to use this for non-rails projects, too!

  5. mattFebruary 27, 2007 @ 11:24 PM

    hell, i’d love for it to be backported to a plugin for 1.2

  6. Stephen TousetFebruary 28, 2007 @ 09:44 AM

    Nice. I already use that style of annotations, so this should be a huge help.

  7. JDFebruary 28, 2007 @ 02:38 PM

    You should be able to use this in any version of rails (just tested it in 1.2.2). Just do this from your rails root:

    svn export http://svn.rubyonrails.org/rails/trunk/railties/lib/tasks/annotations.rake lib/tasks/annotations.rake

  8. RyanFebruary 28, 2007 @ 07:02 PM

    @JD: Thanks for the tip – gonna move it up to the post itself…

  9. ChrisMarch 06, 2007 @ 02:59 AM

    Yes, thank you, love it.

  10. Nate ClarkSeptember 12, 2007 @ 12:19 AM

    This is a great addition, BUT something is broken in my app (running on Edge Rails). Whenever I run any rake task:

    $ rake db:migrate --trace
    (in /home/.dijon/findfuel/releases/20070912040911)
    rake aborted!
    superclass mismatch for class Annotation
    /home/.dijon/findfuel/releases/20070912040911/vendor/rails/railties/lib/tasks/annotations.rake:2
    /home/.dijon/findfuel/releases/20070912040911/vendor/rails/railties/lib/tasks/rails.rb:4:in `load'
    /home/.dijon/findfuel/releases/20070912040911/vendor/rails/railties/lib/tasks/rails.rb:4
    /home/.dijon/findfuel/releases/20070912040911/vendor/rails/railties/lib/tasks/rails.rb:4:in `each'
    /home/.dijon/findfuel/releases/20070912040911/vendor/rails/railties/lib/tasks/rails.rb:4
    /home/findfuel/.packages/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `gem_original_require'
    /home/findfuel/.packages/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `require'
    /home/.dijon/findfuel/releases/20070912040911/Rakefile:10
    /home/findfuel/.gems/gems/rake-0.7.3/lib/rake.rb:1940:in `load'
    /home/findfuel/.gems/gems/rake-0.7.3/lib/rake.rb:1940:in `raw_load_rakefile'
    /home/findfuel/.gems/gems/rake-0.7.3/lib/rake.rb:1727:in `load_rakefile'
    /home/findfuel/.gems/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling'
    /home/findfuel/.gems/gems/rake-0.7.3/lib/rake.rb:1726:in `load_rakefile'
    /home/findfuel/.gems/gems/rake-0.7.3/lib/rake.rb:1710:in `run'
    /home/findfuel/.gems/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling'
    /home/findfuel/.gems/gems/rake-0.7.3/lib/rake.rb:1708:in `run'
    /home/findfuel/.gems/gems/rake-0.7.3/bin/rake:7
    /home/findfuel/.gems/bin/rake:16:in `load'
    /home/findfuel/.gems/bin/rake:16
    

    Any ideas?