简体   繁体   English

如果修复了错误,如何使用Ruby gem?

[英]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? 我已经解决了gem的代码问题,但是如何在Rails 3.0.10应用程序中使用该gem? Do I just include the files in my app or do I need to recompile the gem? 我是否只将文件包含在我的应用程序中,还是需要重新编译gem? If I recompile the gem, how do I use it in my app? 如果我重新编译gem,该如何在我的应用程序中使用它?

Here's 3 ways you could go about this (and I have personally done each one for differing reasons): 您可以通过以下3种方法解决此问题(出于种种原因,我亲自完成了每种方法):

Method 1) 方法1)

  1. Fork the gem if it is on Github (it probably is) 如果宝石在Github上,则将其分叉(可能是)
  2. Make your changes and commit 进行更改并提交
  3. Push the changes to your fork 将更改推送到你的叉子
  4. Source your fork in your Gemfile something like so: 在您的Gemfile中获取叉子,如下所示:

    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. 等待更改被引入并发布新版本,然后更新您的gemfile以停止引用您的fork。

Method 2) 方法2)

  1. copy the gem folder to vendor/gems like so, and edit freely 像这样将gem文件夹复制到供应商/ gem,然后自由编辑
  2. Source that gem folder in your Gemfile like so: 像这样在您的Gemfile中获取该gem文件夹的源:

    gem 'awesome_thing', :path => 'vendor/gems/awesome_thing-0.4.5' gem'awesome_thing',:path =>'供应商/宝石/awesome_thing-0.4.5'

Method 3) 方法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. Monkeypatch仅将您更改的方法和类添加到初始化程序中,直到问题在新版本中得到解决为止。

What you should do is fork the git project that hosts the original gem...make your fixes and push back to git. 您应该做的是分支托管原始gem的git项目...进行修复,然后再推回git。

Then in your Gemfile do: 然后在您的Gemfile中执行以下操作:

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

Then bundle install... 然后捆绑安装...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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