简体   繁体   中英

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?

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM