RI For Your Ruby Gems
June 23rd, 2006
Ruby comes with a great utilty called RI for searching and displaying ruby documentation. I have had varying levels of success in getting this to work with ruby gems so I wanted to share my findings so others may benefit from my trials and errors.
Attempt 1
The first tip I found for this (thanks to Brandt Lofton on the RadRails mailing list) involves modifying your site_ruby/1.8/rubygems/doc_manager.rb by changing this line
r.document(['--quiet', '--op', rdoc_dir]
+ @rdoc_args.flatten + source_dirs)
To:
r.document(['--quiet', '--op', '--merge', '-r', '--ri-system', rdoc_dir]
+ @rdoc_args.flatten + source_dirs)
You must then run the command:
gem rdoc --all
This will install all of your installed gems rdoc documentation for use by Ri.
NOTE: In my experience, this command must complete or the documentation will not be installed properly. For instance, in InstantRails1.3a, the camping-unabridged.rb file causes problems so I renamed it to camping-unabriged.rb-renamed so it will be skipped.
Attempt 2
Some people have experienced problems (myself included) with those steps above. So, I recently tried to find an alternative approach. I found this
post by Eric Hodel, who implemented a different patch for ruby-core.
I tried following in his footsteps, but I was not successful. However, others seem to have gotten that one to work, so you may have better luck than I did.
Attempt 3
If all else fails, they say the third time is the charm. If you can’t get either of those methods to work, there is one more thing you can do to manually install your gem documentation.
This should work for any ruby code you have. Just change directories to the root of the code you want to be able to search with Ri and run this command:
rdoc --ri-site
This will install your documentation into the share/site directory of your ruby install where Ri will be able to read it.
NOTE: I had problems trying to generate the docs for all of my ruby gems at once so you may want to just do this individually for the ones that matter the most, such as actionpack, activerecord etc.
It may seem like a lot of effort just to be able to see your gem documentation from within Ri, but from my personal experience it is completely worth it. Having the ability to instantly look up the Rails documentation has definitely flattened the learning curve for me with Rails as I instantly can see how stuff works, or what the name of that AJAX method is etc.
Enjoy!
Subscribe to the feed!
Leave a Reply