我想让邦德勒装本地宝石。有别的选择吗?或者我必须将gem文件夹移动到.bundle目录?
当前回答
除了指定路径(如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
从文档中可以看到。
其他回答
你也可以用git引用一个本地gem,如果你碰巧正在使用它的话。
gem 'foo',
:git => '/Path/to/local/git/repo',
:branch => 'my-feature-branch'
然后,如果有变化,我就跑
bundle exec gem uninstall foo
bundle update 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'
你可以用source引用宝石:
来源:'https://source.com', git仓库(:github => 'git/url') 使用本地路径
:path => '…/path/gem_name'。
您可以了解更多关于[Gemfiles和如何使用它们] (https://kolosek.com/rails-bundle-install-and-gemfile)。
除了指定路径(如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: "point/to/your/path", branch: "branch-name"
推荐文章
- 如何找到包含匹配值的哈希键
- 未初始化的常量ActiveSupport::Dependencies::Mutex (NameError)
- 如何在Rails中找到当前的路由?
- 在Ruby中->运算符叫什么?
- Rails参数解释?
- Ruby中DateTime和Time的区别
- 如何从代理服务器后面更新Ruby Gems (ISA-NTLM)
- 如何用另一个键替换哈希键
- 添加一个CSS类<%= f.submit %>
- attr_accessor和attr_accessible的区别
- 如何从Ruby文件路径中获得没有扩展名的文件名
- 创建新用户时出现ActiveModel::ForbiddenAttributesError
- rvm安装失败:“rvm不是一个函数”
- rmagick gem安装“无法找到Magick-config”
- 覆盖设计注册控制器