开发者

Lookup Gem or Plugin code packaged in a Rails3 application

开发者 https://www.devze.com 2023-01-07 06:03 出处:网络
In the Rails2 world, one could conveniently browse the code of plugins or gems packaged with the app. With Rails3, all the packaged gems are stored as .gem and hence are not browsable 开发者_如何转开发

In the Rails2 world, one could conveniently browse the code of plugins or gems packaged with the app. With Rails3, all the packaged gems are stored as .gem and hence are not browsable 开发者_如何转开发or searchable. Now I have to use 'bundle open [gem]' externally to browse gem/plugin code. Does anyone have a better technique to lookup or read gem/plugin code instantly


If you install the "gemedit" gem, you can also use gem edit [gem] to open the source of the specified gem. However, gem edit doesn't take bundles into account (I guess it only searches the local gem home), so bundle open is probably the better command within a Rails 3 app.

If you want to keep all gems for an app inside a single directory, you might want to try installing the bundle for the app into a separate directory like with bundle install myBundleDir --disable-shared-gems. This will install all required gems into myBundleDir, ignoring system gems, so you'll have every piece of code that runs your app inside this directory.


Here's something I wrote on my blog a while ago, that helped me solve this problem:

I use gedit to write code. I keep a filebrowser tab open at the left side of my screen, and sometimes I need to look at gem’s source code. RVM is awesome, and it keeps my 1.8.7 gems, 1.9.2 gems and all my gemsets separated, but this makes it tricky to find the gem you need to look at.

Enter RVM hooks! If you want a symlink to the current gem directory to be updated each time you switch ruby versions, save something like the following code to ~/.rvm/hooks/after_use

ln -nfs $rvm_ruby_gem_home/gems ~/src/gems/current_bundle

Now you have access to the source code of gems from the file browser in your editor.

0

精彩评论

暂无评论...
验证码 换一张
取 消