我如何在我的Gemfile中指定一个本地gem?
我想Bundler加载一个本地的gem。 有没有这个选项? 或者我必须将gem文件夹移动到.bundle目录中?
我相信你可以做到这一点:
gem "foo", :path => "/path/to/foo" 除了指定path(如Jimmy提到的)之外,您还可以强制Bundler 只使用以下configuration选项为您的环境使用本地gem:
 $ bundle config local.GEM_NAME /path/to/local/git/repository 
这是非常有用的,如果你正在开发两个gem或一个gem和一个rails应用程序并排。
请注意,这只适用于你已经使用git作为你的依赖,例如:
 # In Gemfile gem 'rack', :github => 'rack/rack', :branch => 'master' # In your terminal $ bundle config local.rack ~/Work/git/rack 
正如在文档中看到的那样 。
你也可以用git来引用一个本地的gem,如果你正在处理它。
 gem 'foo', :git => '/Path/to/local/git/repo', :branch => 'my-feature-branch' 
那么,如果它改变,我跑
 bundle exec gem uninstall foo bundle update foo 
但我不确定每个人都需要执行这两个步骤。
为了在Rails项目中使用本地gem仓库,请按照以下步骤操作:
- 
检查你的gem文件夹是否是一个git仓库(该命令在gem文件夹中执行) git rev-parse --is-inside-work-tree
- 
获取资源库path(该命令在gem文件夹中执行) git rev-parse --show-toplevel
- 
为rails应用程序设置一个本地覆盖 bundle config local.GEM_NAME /path/to/local/git/repository其中 GEM_NAME是你的gem的名称,而/path/to/local/git/repository是第二个点的命令的输出
- 
在您的应用程序 Gemfile添加以下行:gem 'GEM_NAME', :github => 'GEM_NAME/GEM_NAME', :branch => 'master'
- 
运行 bundle install应该是这样的:Using GEM_NAME (0.0.1) from git://github.com/GEM_NAME/GEM_NAME.git (at /path/to/local/git/repository)其中 GEM_NAME是从第2点开始的gem和/path/to/local/git/repository
- 
最后,运行 bundle list,而不是gem list,你应该看到如下所示:GEM_NAME (0.0.1 5a68b88)GEM_NAME是你的gem的名字
我正在观察的几个重要案例:
 Rails 4.0.2 ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux] Ubuntu 13.10 RubyMine 6.0.3 
-   RubyMine似乎并没有将本地的gem作为外部库来显示。 有关错误的更多信息可以在这里和这里find
-  当我改变本地gem中的某些东西时,为了加载到rails应用程序中,我应该stop/startrails服务器
- 
如果我正在更改gem的 version,stopping/startingRails服务器会给我一个错误。 为了解决这个问题,我在rails应用程序Gemfile指定了gem版本,如下所示:gem 'GEM_NAME', '0.0.2', :github => 'GEM_NAME/GEM_NAME', :branch => 'master'
如果你也想分支:
 gem 'foo', path: "point/to/your/path", branch: "branch-name"