如何使用捆绑器创建相互依存的gem,并使用存储库作为源? [英] How to create interdependent gems with bundler, and use repositories as the source?

查看:167
本文介绍了如何使用捆绑器创建相互依存的gem,并使用存储库作为源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建相互依赖的gem,并仍然使用Bundler?



现在,如果 Gemfile for library -a 如下所示:

  gem'library- b'
gem'library -c'

Gemfile for library -b 读起来像这样:

  gem'library -a'
gem'library -c'

code> Gemfile 用于 library-c 内容为:

  gem'library -a',github:'library-root / library -a',分支:'master'
gem'library -b',github:'library-root / library- b',分支:'master'

当您尝试运行 和/或 bundle install 为 library -c ,这是输出:

 您的Gemfile需要依赖于彼此的gem,
创建一个无限循环。请删除gem'library -a'
或gem'library-b'并重试。

同一个消息的变体会发生在 library-a library -b



但是,如果您对 library -c ,并为 library-b library-a 使用相同的样式。 ,这将起作用:

  gem.add_dependency'library -a'
gem.add_dependency'library -b'$然而,现在,您需要将宝石切入并推送给RubyGems来测试每次修订,尤其是使用Travis CI时。而如果您使用 Gemfile 定义,即使您也使用 gemspec 定义,正在运行或测试的代码将会已经从git仓库中取出,并且可以在不切割和推动宝石的情况下进行最新的更新。



我已经发布了两个关于这方面的问题。 / p>



我需要有相互依赖的gem,使用git repositories作为gem代码的源代码。






那些说不做的事 ......它是循环依赖等。我明白了,但让我们来思考一下。宝石真的很复杂吗?这只是具有一定结构的文件。诚然,它具有版本信息和依赖关系 - 但这些依赖关系只是需要存在。如果已经存在适当版本的宝石,它应该只是摆脱循环依赖,并说,嘿,宝石已经在这里,让我们继续前进。






Bundler 是一个包管理系统;以上不是 对象的循环依赖关系它是 文件的依赖关系 / em> ...如果它是对象相互继承,绝对......我投降。但是,这是一个文件系统中存在另一个包的假设。

您可以将单词依赖更改为期望存在而不是需要的顺序实例化。



再次 gemspec 起作用。如果它是循环依赖那是不可能的。但是,作为包管理系统的一部分, gemspec 的目的更为明确。它允许文件成为文件。



gemspec 行为?两个宝石都需要对方?凉!下载这两个宝石。简单,完成。
Gemfile 行为?两个宝石都需要对方?等等,什么? Implode。



我想 gemspec dependency行为, Gemfile 源特异性权力。否则,我只会继续使用 gemspec

解决方案

Bundler是警告你,你的宝石有循环依赖。即库-a取决于库-b,反之亦然。这是应该避免的情况。



如果两个库不能彼此独立存在,最好将它们设为一个。


How is it possible to create interdependent gems, and still use Bundler?

Right now, if the Gemfile for library-a reads like this:

gem 'library-b'
gem 'library-c'

And the Gemfile for library-b reads like this:

gem 'library-a'
gem 'library-c'

And the Gemfile for library-c reads:

gem 'library-a', github: 'library-root/library-a', branch: 'master'
gem 'library-b', github: 'library-root/library-b', branch: 'master'

When you try to run bundle update and/or bundle install for library-c, this is the output:

Your Gemfile requires gems that depend depend on each other,
creating an infinite loop. Please remove either gem 'library-a'
or gem 'library-b' and try again.

A variation of the same message will happen for library-a or library-b.

But if you use the following for library-c, and use the same style for library-b and library-a, this will work:

gem.add_dependency 'library-a'
gem.add_dependency 'library-b'

However now, you will need to cut and push gems to RubyGems to test each revision, especially when using Travis CI. Whereas if you'd used Gemfile definitions, even if you also used gemspec definitions, the code being run or tested would have been pulled from a git repository, and could be updated up-to-the-minute without cutting and pushing gems.

I've posted two issues about this.

I need to have interdependent gems, and use git repositories as the source of the gem code.


For those who say just don't do it ... "it's Circular Dependency", etc. I understand, but let's think about this. Is a gem really that complicated? It's just files with a certain structure. True, it has version information, and "dependencies" associated -- but those dependencies just need to be present. If a gem of the appropriate version exists already, it ought to just break out of a "circular dependency" and say, "hey, the gem's already here, let's just move forward" then.


Bundler is a package management system; the above is not Circular Dependency of objects it is Interdependency of files ... if it were Objects inheriting from each other, definitely... I surrender. But this is a point where one package assumes another exists in the filesystem.

You could change the word depends to expects the presence of not requires specifically sequential instantiation of.

Again gemspec works. If it were Circular Dependency that would be impossible. But gemspec is clearer on its purpose as part of a package management system. It lets files be files.

gemspec behavior? Both gems need each other? Cool! Download both gems. Easy, done. Gemfile behavior? Both gems need each other? Wait, what? Implode.

I want gemspec "dependency" behavior, with Gemfile source specificity power. Otherwise I'd just keep using gemspec only.

解决方案

Bundler is warning you that your gems have a circular dependancy. Namely library-a depends on library-b and the other way around. This is a situation that should be avoided.

If 2 libraries can't exist without each other it's best to just make them one.

这篇关于如何使用捆绑器创建相互依存的gem,并使用存储库作为源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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