Rails 3 | Bundler浅尝

Rails3里多了个Bundler工具。
它是一个Library管理工具,它提供了好的工具来管理你rails3项目依赖的gems。
$> bundle
这个命令会列出bundler提供给你的一些工具。
Tasks:
bundle check # Checks if the dependencies listed in Gemfile are satisfied by currently installed gems
bundle exec # Run the command in context of the bundle
bundle help [TASK] # Describe available tasks or one specific task
bundle init # Generates a Gemfile into the current working directory
bundle install # Install the current environment to the system
bundle lock # Locks the bundle to the current set of dependencies, including all child dependencies.
bundle pack # Packs all the gems to vendor/cache
bundle show # Shows all gems that are part of the bundle.
bundle unlock # Unlock the bundle. This allows gem versions to be changed

你只要在你的Gemfile文件里添加你项目所需的gems就可以了。

$> bundle pack
这个命令可以打包你的gems到vendor/cache目录下。然后你把项目给别的开发者,别人就可以使用:
$> bundle install
来安装项目依赖的gems了。

但是当你想把项目部署到生产环境的话,假如gems出现新版本,可能导致项目出现错误,这个时候,我们就需要锁定gem的版本。
$> bundle lock
这个命令会在rails的根目录下生成一个Gemfile.lock文件。类似于这样的:
---
dependencies:
- rails: = 3.0.0.beta
- sqlite3-ruby: ">= 0"
- pg: ">= 0"
specs:
- text-hyphen:
version: 1.0.0
- builder:
version: 2.1.2
- i18n:
version: 0.3.3

当你在Gemfile文件里增加了一个新的gem,比如“hpricot”你运行:
$> bundle check
You changed your Gemfile after locking. Please relock using `bundle unlock`
想修改Gemfile必须先解锁Gemfile文件:
$> bundle unlock
然后才能修改,修改完再锁定。
$> bundle install
这条命令会自动安装Gemfile里的所有gem。
然后我们再检测:
$>bundle check
The Gemfile's dependencies are satisfied
这就安全了。
然后我们可以打包了:
$> bundle pack
Copying .gem files into vendor/cache
...
打包完以后,锁定我们的gems:
$> bundle lock
这下你就可以安全部署你的app了。

gem的写法可以具体参照:http://github.com/carlhuda/bundler
Bundler官网:http://gembundler.com

本文出自 “{ :Alex Space => &..” 博客,请务必保留此出处http://blackanger.blog.51cto.com/140924/355320
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值