tollbooth
tollbooth

Reputation: 423

How do I use a Ruby gem if I fixed a bug?

I resolved a code issue with a gem, but how do I then use that gem in my Rails 3.0.10 app? Do I just include the files in my app or do I need to recompile the gem? If I recompile the gem, how do I use it in my app?

Upvotes: 1

Views: 222

Answers (2)

Unixmonkey
Unixmonkey

Reputation: 18784

Here's 3 ways you could go about this (and I have personally done each one for differing reasons):

Method 1)

  1. Fork the gem if it is on Github (it probably is)
  2. Make your changes and commit
  3. Push the changes to your fork
  4. Source your fork in your Gemfile something like so:

    gem 'awesome_thing', :git => 'git://github.com/yourname/awesome_thing.git'

  5. Send pull request and polite note to current maintainer (optional)

  6. Wait for changes to be pulled in and a new version released then update your gemfile to stop referencing your fork.

Method 2)

  1. copy the gem folder to vendor/gems like so, and edit freely
  2. Source that gem folder in your Gemfile like so:

    gem 'awesome_thing', :path => 'vendor/gems/awesome_thing-0.4.5'

Method 3)

  1. Monkeypatch just the methods and classes you changed and put them in an initializer until the problem is fixed in a new version.

Upvotes: 5

Webjedi
Webjedi

Reputation: 4737

What you should do is fork the git project that hosts the original gem...make your fixes and push back to git.

Then in your Gemfile do:

gem 'gemyoufixed', git: 'git://github.com/you/gemyoufixed'

Then bundle install...

Upvotes: 3

Related Questions