简体   繁体   English

如何在捆绑程序中包含.gem文件(不是源文件)

[英]How to include a .gem file in bundler (not source)

I have a rails app that is dependent on a library that I'm developing simultaneously. 我有一个Rails应用程序,它依赖于同时开发的库。

When I deploy the app, I don't have the option to use :git => '' option in bundler to load in the gem for various reasons. 部署应用程序时,出于各种原因,我没有选择在捆绑程序中使用:git =>''选项来加载gem。 Ideally what I want to do is the following 理想情况下,我要执行的操作如下

Gemfile 宝石文件

gem 'system-api', :gem => 'vendor/system-api-1.0.0.gem'

I want to pre-build the gem and simply include it into the project and check it into git. 我想预构建gem并将其简单地包含到项目中,然后将其检入git。

Is there a way to do this with bundler or even without using bundler? 有没有办法使用捆绑器甚至不使用捆绑器来做到这一点?

[UPDATE 1] [更新1]

I tried "gem 'system-api','1.0.0', :path => 'vendor/' " and bundler says it installed correctly, but the gem doesn't show up in 'gem list' nor does the rails project have a reference to it. 我尝试了“ gem'system-api','1.0.0',:path =>'vendor /'”,捆绑程序说它已正确安装,但是gem没有显示在'gem list'中,rails项目也没有有一个参考。 It is shown with the 'bundle show' command. 它与“捆绑包显示”命令一起显示。

I did the following, which works: 我做了以下工作:

gem 'libv8', '3.11.8.3mytest', :path => '../libv8/pkg'

And the ../libv8/pkg folder contains only the binary packaged gem libv8-3.11.8.3mytest-x86_64-linux.gem . ../libv8/pkg文件夹仅包含二进制打包的宝石libv8-3.11.8.3mytest-x86_64-linux.gem

Hope this helps. 希望这可以帮助。

It looks like bundler has a :path option. 看来bundler具有:path选项。 It'll run relative to the project's Gemfile location. 它将相对于项目的Gemfile位置运行。 The path only specifies the folder, not the actual gem name: 该路径仅指定文件夹,而不指定实际的gem名称:

gem 'system-api', :path => "vendor"

See bundler's Gemfile docs for more info. 有关更多信息,请参见捆绑程序的Gemfile文档

It MIGHT work if you put the X.gem file into ./vendor/cache 如果将X.gem文件放入./vendor/cache,则可能会起作用

If you run "bundle package", then that's where bundler will put built .gem files. 如果运行“捆绑包”,则捆绑器将在其中放置内置的.gem文件。 So if you put it there yourself, will bundler find it there? 因此,如果您自己将其放在此处,捆扎机会在此处找到它吗? Maybe. 也许。 But I'm not sure about the idea of having some gems packaged in ./vendor/cache and others not, not entirely sure if Bundler supports that, since I think "bundle package" insists on putting all of em in there. 但是我不确定在./vendor/cache中打包一些宝石,而其他人不打包的想法,也不完全确定Bundler是否支持,因为我认为“捆绑包”坚持将所有em放在其中。

http://gembundler.com/bundle_package.html http://gembundler.com/man/bundle-package.1.html http://gembundler.com/bundle_package.html http://gembundler.com/man/bundle-package.1.html

If instead of checking your pre-built X.gem into your repo, you can check the SOURCE for the X gem into your repo, and the source includes an X.gemspec file, THEN you can use the :path option. 如果不是将预先构建的X.gem检入到存储库中,而是可以将X gem的源检查到存储库中,并且源文件包含X.gemspec文件,则可以使用:path选项。 But I think as you've discovered the :path option expects to point at source, not a *.gem package. 但是我认为,您已经发现:path选项希望指向源,而不是* .gem包。 It's possible that if you simply unzip the *.gem, that will result in a directory that you can use bundler gem :path with. 如果仅将* .gem解压缩,则可能会生成一个目录,您可以在其中使用bundler gem:path。 (A *.gem product is just a zipfile... I think.). (* .gem产品只是一个zip文件...我想。)

Not a definitive answer, but some ideas to explore maybe. 这不是一个确定的答案,但是可能需要探索一些想法。

I would say it's normal gem list does not show your gem. 我会说这是正常的gem list ,不会显示您的宝石。 You installed it through bundler, and you don't invoke bundler when running gem list . 您是通过捆绑程序安装的,运行gem list时不会调用捆绑程序。 Instead, check with bundler exec gem list . 相反,请检查bundler exec gem list

By the way, when using Bundler you should always use bundler exec before any command line you run (with the exception of rails server which has its own way to get Bundler up and running): bundle-exec man page 顺便说一句,在使用Bundler时,应始终在运行任何命令行之前使用bundler execrails server除外,它具有自己的方式来启动和运行Bundler): bundle-exec手册页

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM