条件 gem 依赖 [英] Conditional gem dependencies

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

问题描述

是否可以在安装时有条件地设置对 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.

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

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.

谁有好的解决办法?

推荐答案

嗯,

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

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.

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

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.

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

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