相互冲突的红宝石宝石 [英] conflicting ruby gems

查看:110
本文介绍了相互冲突的红宝石宝石的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的项目中使用两个声明PDF名称空间的gem:pdf-reader和htmldoc。



有什么方法可以让他们玩得很好一起?我能想到的唯一方法就是重写我自己的htmldoc版本,给它一个不同的命名空间。

解决方案

可能没有优雅的解决问题的方法。如果你真的需要两个宝石并肩工作,我认为你最好的选择是分叉其中一个(或可能两个)并使用你的叉子。这是我如何去做的:




  • 如果gem托管在Github上,然后分叉它,或者如果两者都在Github fork似乎是最不起作用的。

  • 如果两个gem都不在Github上,看看你是否可以获得源代码(从gem中获取它是一种可能性,但找到真正的存储库可能会有所帮助,因为那里可能有其他文件没有包含在gem中),并将其放入Github上的存储库中。确保gem的许可证允许这样做(如果它是常见的开源许可证之一,它几乎肯定会这样做)。

  • 进行更改。

  • 确保存储库根目录中有一个 .gemspec 文件,否则下一步将不起作用。

  • 使用 Bundler 来管理您的项目依赖关系。而不是指定你修改过的库的依赖关系

      gem'the_gem'
      gem 

    'the_gem',:git => 'git://github.com/you/the_gem.git'

    (但将网址更改为将存储库转换为实际的存储库)

  • 发送电子邮件给您修改的gem的维护人员,并要求他/她考虑合并您的更改下一个版本。


Bundler使得使用其他版本的gem非常简单,我经常分叉宝石,修正错误或添加功能,将我的 Gemfile 更改为指向我的版本,然后请维护人员合并我的更改。何时或如果发生这种情况,我只需将 Gemfile 更改为仅指正式版本的宝石。



< p另一种策略是,如果维护者不想合并你的更改,并且你想将你的版本分发给其他人,那么将你的版本作为一个新的gem推到Rubygems上,但是在这种情况下,在你的名字前加上你的名字,或者其他一些字符串,将您的宝石识别为变体。


I need to use two gems in my project that both claim the PDF namespace: pdf-reader and htmldoc.

Is there any way to get them to play nice together? The only way I can think of is to rewrite my own version of htmldoc to give it a different namespace.

解决方案

There's probably no elegant solution to the problem. If you really need the two gems working side by side I think your best option is to fork one of them (or possibly both) and use your fork. This is how I'd go about it:

  • If either gem is hosted on Github then fork it, or if both are on Github fork the one that seems to be the least work.
  • If neither gem is on Github, see if you can get hold of the source (grabbing it from the gem is a possibility, but finding the real repository might be helpful as there may be other files there that are not included in the gem), and put it in a repository on Github. Make sure the gem's license allows this (which it almost certainly does if it's one of the common open source licenses).
  • Make your changes.
  • Make sure there is a .gemspec file in the root of the repository, the next step will not work otherwise.
  • Use Bundler to manage your projects dependencies. Instead of specifying the dependency to the library you've modified as

    gem 'the_gem'
    

    specify it like this:

    gem 'the_gem', :git => 'git://github.com/you/the_gem.git'
    

    (but change the URL to the repository to the actual one)

  • Send an e-mail to the maintainer of the gem you modified and ask him or her to consider merging in your changes in the next release.

Bundler makes it really easy to use alternative versions of gems with minimal hassle. I often fork gems, fix bugs or add features, change my Gemfile to point to my version, then ask the maintainer to merge in my changes. When, or if, that happens I simply change my Gemfile back to just refer to the official version of the gem.

An alternative strategy, if the maintainer does not want to merge in your changes and you want to distribute your version to others is to push up your version to Rubygems as a new gem, but in that case prefix the gem name with your name, or some other string that identifies your gem as a variant.

这篇关于相互冲突的红宝石宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆