readrails alias to open Textmate with the Rails gems source code

Now that Rails 1.2 is out, and you switched to using the gems instead of Edge, you might find yourself having “a hard time” searching the Rails source code. Enter: a Bash alias to opening the Rails source in Textmate.


# readrails - an alias to open Textmate with the Rails source from Gems
# You need the GEM_HOME folder set to where your gems are (this is for portability)
# export GEM_HOME=/usr/local/lib/ruby/gems/1.8 # this is my GEM_HOME setting

export GEMSFOLDER="${GEM_HOME}/gems/" 
alias readrails="e ${GEMSFOLDER}rails-1.2.1 ${GEMSFOLDER}activerecord-1.15.1 ${GEMSFOLDER}actionwebservice-1.2.1 ${GEMSFOLDER}activesupport-1.4.0"

If the above is garbled, see this paste.

Problem in the above: the version numbers. They increase with each new release of these gems. A more polished version of this alias could look at the version numbers after the last dash, and figure out what version to use.

Update! Stop the presses!

Jonas B just made my thing lots better, by invoking Rubygems itself!

I wrapped his couple of lines into my alias, like this:


#
# readrails 0.2 - an alias to open Textmate with the Rails source from Gems
#

alias readrails="mate `ruby -rubygems -e "puts( ['rails', 'activerecord', 'actionwebservice', 'actionpack', 'activesupport'].collect { |gem| gems = Gem.source_index.find_name(gem); gems.last.full_gem_path; }.join(' '))"`"

And I pasted it at: http://pastie.caboo.se/36928 — this is getting better and better.

If you’d like to make it better still, just work Jonas’ original error-checking into the above as well:


paths = ['rails', 'activerecord', 'actionwebservice', 'activesupport'].collect do |gem|
gems = Gem.source_index.find_name gem
raise "gem '#{gem}' not found" if gems.empty?
gems.last.full_gem_path
end
paths.join ' '

Published by olleolleolle

Olle is a programmer, enjoying sunny Malmö in Sweden.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.