开箱/冻结宝石成非轨道红宝石应用程序 [英] unpacking/freezing gems into a non-rails ruby app

查看:91
本文介绍了开箱/冻结宝石成非轨道红宝石应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写非Rails ruby​​应用程序(gasp!),并希望能够在供应商子目录中包含应用程序所需的所有gem依赖项。这与 http://gemsonrails.rubyforge.org/ 适用于Rails应用程序的方式类似。

这里的目标是避免我的团队在添加新的依赖关系时遇到的情况。我的团队中的每个开发人员都必须手动安装gem,然后有人必须手动更新每个测试和分段和生产计算机。如果我们可以将依赖关系冻结到分布式应用程序本身中,那么只需要一个简单的svn更新(或者适用于人群中的那些时髦人员的git pull)即可。

解决方案

更新(新解决方案):



尝试Yehuda Katz的新 bundler 宝石。 gem install bundler 然后用你所有的依赖关系创建一个 Gemfile 。请参阅文档获取更多信息。



旧建议:

一种简单的方法只是手动将宝石解包到供应商目录中,并将解压后的宝石的lib路径添加到$ LOAD_PATH的前面。



解开宝石:

  $ cd供应商/宝石
$ gem解压active_support
解包的gem:'/path/to/myproject/vendor/gems/activesupport-2.3.2'



<只要确保你解开所有必要的宝石及其依赖关系(使用正确的版本)。

要将供应商/宝石下的所有宝石添加到您的$ LOAD_PATH中,请尝试添加类似于你的应用程序的初始化:

  Dir.glob(File.join(vendor,gems, *,lib))。each do | lib | 
$ LOAD_PATH.unshift(File.expand_path(lib))
end

更新: Sarah(在评论中)确信我可能有必要重写GEM_PATH。这是一种方法:

$ $ p $ require'rubygems'
gem_paths = [File.expand_path(File.join( vendor,gems)),Gem.default_dir]
Gem.clear_paths
Gem.send:set_paths,gem_paths.join(:)






另一个选项是查看 Rip (Ruby的智能打包)来管理你的依赖关系。瑞普看起来非常甜蜜,但它仍然是新的。


I'm writing a non-Rails ruby application (gasp!) and would like to be able to include all the gem dependencies which the application requires in a vendor subdirectory. This would be similar to how http://gemsonrails.rubyforge.org/ works for Rails apps.

The goal here is to avoid the situation my team currently experiences when a new dependency is added. Every developer on my team has to install the gem manually, and then someone has to manually update each test and staging and production machine. If we can freeze the dependencies into the distributed application itself then a simple svn update (or git pull for those hipsters in the crowd) would be all that is needed.

解决方案

UPDATE (New Solution):

Try Yehuda Katz's new bundler gem. gem install bundler then create a Gemfile with all your dependencies. See the documentation for more info.

Old Recommendation:

One easy way is to just manually unpack the gems into your vendor directory and add the lib path of the unpacked gems to the front of the $LOAD_PATH.

To unpack a gem:

$ cd vendor/gems
$ gem unpack active_support
Unpacked gem: '/path/to/myproject/vendor/gems/activesupport-2.3.2'

Just make sure you unpack all the necessary gems and their dependencies (using the correct versions).

To add all gems under vendor/gems to your $LOAD_PATH, try adding something like this to your application's initialization:

Dir.glob(File.join("vendor", "gems", "*", "lib")).each do |lib|
  $LOAD_PATH.unshift(File.expand_path(lib))
end

Update: Sarah (in the comments) convinced me it might also be necessary to override the GEM_PATH. Here's one way to do that:

require 'rubygems'
gem_paths = [File.expand_path(File.join("vendor", "gems")),  Gem.default_dir]
Gem.clear_paths
Gem.send :set_paths, gem_paths.join(":")


Another option is to look into Rip (Ruby’s Intelligent Packaging) for managing your dependencies. Rip looks really sweet, but it's still new.

这篇关于开箱/冻结宝石成非轨道红宝石应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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