The simple way to have your gem and eat it too: Symlinks to the rescue (Ruby on Rails Tip!)

Here's how to have your gem and eat it too. It's been quite a pain previously to try and a) modify functionality in a gem and b) also use it in a working dev project directory.

Previously, I've had to resort to git submodules or other horrendous integration points. But now (this is SO simple) I realize all I have to do is:
  1. Fork or check in your gem to github. Fully follow the instructions by github.
  2. Add config.gem 'username-gemname', :source => 'http://gems.github.com' to your environment.rb file.
  3. Now in your local rails project directory, under vendor/gems you can create a symlink from your local dev copy of your gem to username-gemname, e.g. garrytan-ebayapi-0.12.1

Tada! Now your production / staging / other development instances (and your dev buddies) will pick up whatever is checked in as a gem, but you'll be able to mess around with your local copy of the gem and work on it without any hassle.

Don't forget to update your VERSION, generate a new gemspec, and push to github to make sure everyone else picks up your changes when you're done making changes to your gem.
views
6 responses
Interesting that you find git submodules to be horrendous. They seem to work quite well for me.

Under your scheme, how can another developer make a change to the gem in question? Or you, if you are trying the code on another box and want to fix a bug? You can't fix it right then and there; you need to do a separate pull of the gem from it's repo, etc. Seems that using a symlink makes it easier for one person on one box, but less useful than submodules for anyone else.

This is true. It's just not as good for multiple people on a gem.

Still, to get submodules to work with capistrano, you have to use capistrano deepmodule plugins, which are a pain. Also adds to deploy time for no real benefit.

I've been more focused on desktop development, so submodules work real well when I need to fix something on different machines, push changes back, then re-test on another platform.
What a stupid tip. This blog sucks.
Brad, your face sucks.
1 visitor upvoted this post.