我想让邦德勒装本地宝石。有别的选择吗?或者我必须将gem文件夹移动到.bundle目录?


当前回答

为了在Rails项目中使用本地gem存储库,请遵循以下步骤:

Check if your gem folder is a git repository (the command is executed in the gem folder) git rev-parse --is-inside-work-tree Getting repository path (the command is executed in the gem folder) git rev-parse --show-toplevel Setting up a local override for the rails application bundle config local.GEM_NAME /path/to/local/git/repository where GEM_NAME is the name of your gem and /path/to/local/git/repository is the output of the command in point 2 In your application Gemfile add the following line: gem 'GEM_NAME', :github => 'GEM_NAME/GEM_NAME', :branch => 'master' Running bundle install should give something like this: Using GEM_NAME (0.0.1) from git://github.com/GEM_NAME/GEM_NAME.git (at /path/to/local/git/repository) where GEM_NAME is the name of your gem and /path/to/local/git/repository from point 2 Finally, run bundle list, not gem list and you should see something like this: GEM_NAME (0.0.1 5a68b88) where GEM_NAME is the name of your gem


以下是我观察到的一些重要案例:

Rails 4.0.2  
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux] 
Ubuntu 13.10  
RubyMine 6.0.3

It seems RubyMine is not showing local gems as an external library. More information about the bug can be found here and here When I am changing something in the local gem, in order to be loaded in the rails application I should stop/start the rails server If I am changing the version of the gem, stopping/starting the Rails server gives me an error. In order to fix it, I am specifying the gem version in the rails application Gemfile like this: gem 'GEM_NAME', '0.0.2', :github => 'GEM_NAME/GEM_NAME', :branch => 'master'

其他回答

除了指定路径(如Jimmy提到的),您还可以通过使用以下配置选项强制Bundler仅为您的环境使用本地gem:

$ bundle config set 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 set local.rack ~/Work/git/rack

从文档中可以看到。

我相信你能做到:

gem "foo", path: "/path/to/foo"

为了在Rails项目中使用本地gem存储库,请遵循以下步骤:

Check if your gem folder is a git repository (the command is executed in the gem folder) git rev-parse --is-inside-work-tree Getting repository path (the command is executed in the gem folder) git rev-parse --show-toplevel Setting up a local override for the rails application bundle config local.GEM_NAME /path/to/local/git/repository where GEM_NAME is the name of your gem and /path/to/local/git/repository is the output of the command in point 2 In your application Gemfile add the following line: gem 'GEM_NAME', :github => 'GEM_NAME/GEM_NAME', :branch => 'master' Running bundle install should give something like this: Using GEM_NAME (0.0.1) from git://github.com/GEM_NAME/GEM_NAME.git (at /path/to/local/git/repository) where GEM_NAME is the name of your gem and /path/to/local/git/repository from point 2 Finally, run bundle list, not gem list and you should see something like this: GEM_NAME (0.0.1 5a68b88) where GEM_NAME is the name of your gem


以下是我观察到的一些重要案例:

Rails 4.0.2  
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux] 
Ubuntu 13.10  
RubyMine 6.0.3

It seems RubyMine is not showing local gems as an external library. More information about the bug can be found here and here When I am changing something in the local gem, in order to be loaded in the rails application I should stop/start the rails server If I am changing the version of the gem, stopping/starting the Rails server gives me an error. In order to fix it, I am specifying the gem version in the rails application Gemfile like this: gem 'GEM_NAME', '0.0.2', :github => 'GEM_NAME/GEM_NAME', :branch => 'master'

如果你也想要分支:

gem 'foo', path: "point/to/your/path", branch: "branch-name"

你也可以用git引用一个本地gem,如果你碰巧正在使用它的话。

gem 'foo',
  :git => '/Path/to/local/git/repo',
  :branch => 'my-feature-branch'

然后,如果有变化,我就跑

bundle exec gem uninstall foo
bundle update foo

但我不确定每个人都需要执行这两个步骤。