Ruby-on-rails 我如何为 Rails3/Bundler 供应 gems

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3646847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:09:56  来源:igfitidea点击:

How do I vendorize gems for Rails3/Bundler

ruby-on-railsruby-on-rails-3bundler

提问by troelskn

In Rails 2.X, I could simply copy gems into vendor/gems/gem_name, or use the rake command rake gems:unpack. Since Rails3 uses bundler, it doesn't appear to work anymore. I have found the command bundle package, but it doesn't work the same way.

在 Rails 2.X 中,我可以简单地将 gems 复制到 中vendor/gems/gem_name,或者使用 rake 命令rake gems:unpack。由于 Rails3 使用捆绑器,它似乎不再起作用。我找到了 command bundle package,但它的工作方式不同。

Edit:

编辑:

So, just to elaborate a bit on this:

所以,只是详细说明一下:

The way that rails 2 worked, I could easily grepto find stuff in vendor/gems. If they are bundled up in .gemfiles, that isn't possible. Also, when developing a gem/plugin, it's very helpful to have it placed within a rails application to test it out in context. How would I do such things with bundler/rails3? Is my workflow inherently broken somehow?

rails 2 的工作方式,我可以轻松地grepvendor/gems. 如果它们捆绑在.gem文件中,那是不可能的。此外,在开发 gem/插件时,将其放置在 rails 应用程序中以在上下文中对其进行测试非常有帮助。我将如何使用 bundler/rails3 做这些事情?我的工作流程是否天生就以某种方式被破坏了?

回答by oma

Answering the second part of your question, developing a plugin/gem and shipping it with the rails app without making the gem publicly available, you may do this

回答问题的第二部分,开发插件/gem 并将其与 rails 应用程序一起发布,而不将 gem 公开,您可以这样做

Gemfile

文件

gem 'my_private_gem', :path => "vendor/gems/my_private_gem-VERSION"

assuming you performed a gem unpack my_private_gem --target vendor/gems

假设你执行了一个 gem unpack my_private_gem --target vendor/gems

note: bundle packageunpacks all gems (as many as in Gemfile.lock). I wouldn't want those in git.

注意:bundle 包会解压所有 gems(与 Gemfile.lock 中的一样多)。我不想要那些在 git 中的。

回答by John Topley

The Bundler equivalent isbundle package. It packages all of the .gem files specified in the Gemfile into vendor/cacheso that future installs get the gems from this cache rather than from http://rubygems.org/

Bundler 等价物bundle package。它将 Gemfile 中指定的所有 .gem 文件打包到其中,vendor/cache以便将来的安装从该缓存而不是从http://rubygems.org/获取 gem

回答by Matijs van Zuijlen

The correct Bundler equivalent is bundle install --deployment. This will install the gems, in their unpacked state, in vendor/bundle.

正确的 Bundler 等价物是bundle install --deployment. 这将在vendor/bundle.

回答by jsears

This is what worked for me:

这对我有用:

gem unpack <GEM_NAME> [-v <VERSION>] --target vendor/gems
gem specification <GEM_NAME> [-v <VERSION>] --ruby > vendor/gems/<GEM_NAME>[-<VERSION>].gemspec

For example:

例如:

gem unpack sidekiq-pro -v 2.1.4 --target vendor/gems
gem specification sidekiq-pro -v 2.1.4 --ruby > vendor/gems/sidekiq-pro-2.1.4.gemspec

The first command unpacks the gem into the vendor/gems directory. However, that doesn't contain the gemspec. The second command creates the associated gemspec. It's noteworthy that another poster mentioned something similar. This solution correctly writes the gemspec in ruby format instead of in yaml.

第一个命令将 gem 解压到 vendor/gems 目录中。但是,它不包含 gemspec。第二个命令创建关联的 gemspec。值得注意的是,另一张海报提到了类似的事情。此解决方案以 ruby​​ 格式而不是 yaml 正确写入 gemspec。

You can then update your Gemfile to point to the vendored gem:

然后你可以更新你的 Gemfile 以指向 vendored gem:

gem '<GEM_NAME>', '<VERSION>', :path => "vendor/gems/<GEM_NAME>-<VERSION>"

For example:

例如:

gem 'sidekiq-pro', '2.1.4', :path => "vendor/gems/sidekiq-pro-2.1.4"

回答by Alex Fortuna

Consider using "hosted" development infrastructure delivered by the hosted_gem_developmentgem.

考虑使用由hosted_gem_developmentgem提供的“托管”开发基础设施。

Developing gems is often tricky because they act like separate projects with regard to the applications you use them in.

"Hosted" development infrastructure makes gem development easier by including them into (making them "hosted by") your live application. Then you update your gem's code like you update regular application code.

开发 gems 通常很棘手,因为对于您在其中使用它们的应用程序,它们就像单独的项目一样。

“托管”开发基础设施通过将它们包含到(使它们“托管于”)您的实时应用程序中来使 gem 开发更容易。然后像更新常规应用程序代码一样更新 gem 的代码。

Go to project page

进入项目页面