有条件的宝石依赖 [英] Conditional gem dependencies

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

问题描述

是否可以在安装时有条件地设置gem的依赖关系?这是我的情况,希望能够澄清这个问题。



我有一个宝石取决于json宝石。但是,我经常使用jruby,它有一个名为json-jruby的json gem的端口。要解决这个问题,我必须为每个依赖构建两个独立的gem。我想要构建一个gem,要么说它依赖于json或json-jruby,要么在安装时检查并使用正确的依赖关系。

任何人都可以很好的解决这个问题吗?



我相信可以编写多个依赖项,因为我注意到似乎这样做的宝石。但我会建议不要这样做。不管你在这里插入的代码有多简单,当你考虑到用户将加载一个依赖于另一个依赖于另一个的gem时,即使是一段代码或另一段代码的逻辑中的小故障也可以使整体依赖训练一场噩梦。



所以,我会按原样离开你的kludge。此外,我建议你有一个tarball,用户也可以下载。我不得不手动提取配置代码不允许我安装它们的gem中的代码。

Is it possible to conditionally set a dependency on a gem at install time? Here's my situation which will hopefully clarify the question.

There is a gem I maintain that depends on the json gem. However, I frequently use jruby which has a port of the json gem that's called json-jruby. To work around this I have to build two separate gems for each dependency. I'd like to build one gem that either says it depends on json OR json-jruby, or it checks at install time and uses the right dependency.

Anyone have a good solution to this?

解决方案

Hmm,

I believe one can code multiple dependencies because I've noticed gems which seemed to do this. But I would you advise against doing this. No matter how simple the code you are inserting here is, when you consider that the user will be loading one gem which depends on another which depends on another, even a small glitch in the logic of one piece of code or another can make the whole dependency train a nightmare.

So, I'd leave your kludge as-is. Further, I'd suggest you have a tarball that users can download as well. I've had to manually extract the code inside of gems whose configuration code wouldn't let me install them.

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

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