管理红宝石宝石的冲突版本 [英] Managing conflicting versions of ruby gems

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

问题描述

我正在构建一个加载用户提供的Ruby代码的框架。它基本上是一个插件机制。我希望用户提供的Ruby代码能够要求自己的宝石。我打算让插件包中包含一个包含宝石的供应商目录。



如何加载插件所需的宝石,而不会与我的框架冲突宝石?例如,如果我的框架使用treetop版本1.3.0,并且插件使用treetop 1.4.2,我希望每个都使用它们的指定版本。



同样,有没有办法阻止插件互相冲突?

我看过gem_plugin ,_why的沙箱以及其他一些工具。但我没有看到任何专门处理这种情况的库 - 我假设它已经完成了。



我还查看了Bundler的内部,了解它如何管理宝石版本。如果需要,我准备做一些非常复杂的事情。但我仍然不确定如何去做。



我也有很多自由来实现这一点。所以如果你认为我吠叫错了树,请说出来。



感谢您的任何建议。



SIDE注意:在写这篇文章时我想到了我需要类似于Java servlet容器中的类加载器的东西。 WAR文件可以包含jar文件,Web应用程序的类加载器将优先于全局类路径上的jar文件。有没有什么办法在红宝石细分红宝石classpath(即load_path,要求等)?

解决方案

,您不能同时加载同一个gem的两个版本。

Bundler在查看所有必需的gem并找到各种重叠依赖的解决方案方面做了很好的工作,但即使如此,它也仅限于加载一次一个版本的宝石。



这导致插件开发者不断需要更新以支持在相关gem中进行的任何更改,以避免您描述的情况。



(不要让我开始讨论各种竞争JSON实现所带来的困难,以及当您需要不同的gem依赖时,您必须经历的痛苦。) p>

I am building a framework that loads user provided ruby code. It is basically a plugin mechanism. I want the user provide ruby code to be able to require gems of its own. I intend to have the "plugin" package include a vendor directory with the gems.

How can I load gems that are required by the plugin without having them conflict with my framework's gems? For example, if my framework uses treetop version 1.3.0, and a plugin uses treetop 1.4.2 I want each to work with their specified version.

Likewise, is there a way to prevent plugins from conflicting with each other?

I have looked at gem_plugin, _why's sandbox, and some other tools. But I don't see any library that specifically handles this case - I assume its been done before.

I have also looked at the internals of Bundler to see how it manages gem versions. I am prepared to do some pretty complex stuff if need be. But I am still uncertain of how to go about it.

I also have a lot of freedom in how I implement this. So if you think I am barking up the wrong tree, please say so.

Thanks for any advice.

SIDE NOTE: It occurred to me while writing this that I need something similar to the Classloaders in a Java servlet container. A WAR file can include jar files, and the web application's class loader will prefer those over the jars that are on the global classpath. Is there any way in ruby to segment the ruby "classpath" (i.e. load_path, require, etc)?

解决方案

To be blunt, you can't have two versions of the same gem loaded at the same time.

Bundler does a good (ish) job of looking through all of the required gems and finding a solution to the various overlapping dependencies, but even so it is limited to only loading one version of a gem at a time.

This leads to plugin developers constantly having to update to support any changes that are made in dependent gems in order to avoid just the situation you describe.

(Don't get me started on the screw up that results from the various competing JSON implementations and the pain you have to go through when you have several gem dependencies all requiring different ones.)

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

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