Forking a gem for a Rails project

Today this is pretty easy to do with Bundler. You make a local copy of the gem and then instead of doing

gem "whatever"

in your Gemfile, you do:

gem "whatever", :path => "/home/pupeno/whatever"

After running bundle install, the gem is picked from that directory. Even if you modify something in there, all you need to do to re-load it is restart Rails.

If you need to deploy an application using your own changes of a Gem, you make a fork, on Github or similar and on the Gemfile you do:

gem "whatever", :git => "[email protected]:/pupeno/whatever.git"

and that's it. It's simple, straightforward and beautiful.


In all the cases the gems were at github so I would probably for it at github, clone it, make my chances and maintain my own branch. I suppose then I would install that branch directly with gem install on my server.

If you really need to hack the actual gem source then yes, that would be the way to do it. However, it should be a last resort. You don't want to maintain the actual gem if you don't have to. Why not extend classes from the gem source whose functionality you need to change and use your classes instead of the gem classes in your Rails code?

I find it rare that you actually need to hack 3rd party code directly to do what you need to do. Good software can be extended/easily augmented.