Manage conflicting ruby ​​gem versions

I am creating a framework that loads a user-provided ruby ​​code. This is basically a plugin mechanism. I want the user to provide a ruby ​​code to be able to claim their own gems. I intend to have a “plugin” package that includes a vendor catalog with precious stones.

How can I download the gems that the plugin needs without conflict with my frames? For example, if my framework uses treetop version 1.3.0, and the plugin uses treetop 1.4.2, I want everyone to work with their specified version.

Also, is there a way to prevent plugin conflicts with each other?

I looked at gem_plugin, _why sandbox and some other tools. But I do not see a library that specifically handles this case - I assume that it was done before.

I also looked at the insides of the Bundler to see how it manages gem versions. If necessary, I am ready to do some pretty complicated things. But I'm still not sure how to do this.

I also have a lot of freedom in how I implement this. Therefore, if you think that I bark on the wrong tree, say so.

Thanks for any advice.

SIDE NOTE: When writing this, it occurred to me that I needed something similar to Classloaders in a Java servlet container. The WAR file may include jar files, and the web application class loader prefers those above banks that are in the global class path. Is there a way in ruby ​​to segment the ruby ​​“classpath” (ie Load_path, require, etc.)?

+2
ruby plugins version rubygems
source share
2 answers

To be dumb, you cannot download two versions of the same gem at the same time.

Bundler does a good (ish) job of looking at all the necessary gems and finding a solution for different overlapping dependencies, but it is only limited to downloading one version of the gem at a time.

This leads to the fact that plug-in developers have to constantly update to support any changes made to dependent gems in order to avoid the described situation.

(Don't make me start with a screw that results from various competing JSON implementations, and the pain you have to go through when you have several gem addictions that require different gems).

+5
source share

Regards, I do not agree with the answer above. Here is how I do it:

ruby -S gem list my_gem

 `*** LOCAL GEMS *** my_gem (1.0.1, 1.0.0, 0.0.2) ` 

ruby -S gem lock my_gem-1.0.0 > locklist.rb

which generates a dependency list for a specific version in the locklist

 require 'rubygems' gem 'my_gem', '= 1.0.0' gem 'gem_base', '= 1.0.0' gem 'rest-client', '= 1.7.2' gem 'savon', '= 1.1.0' gem 'addressable', '= 2.3.6' gem 'mime-types', '= 1.25.1' gem 'netrc', '= 0.11.0' 

now you can do load('locklist.rb') , which will load a specific version of the gem along with its dependencies. Look, ma, there is no Bundler.

0
source share

All Articles