I'd like Bundler to load a local gem. Is there an option for that? Or do I have to move the gem folder into the .bundle directory?
我希望邦德勒能装载当地的宝石。有选择的余地吗?还是必须将gem文件夹移动到.bundle目录中?
6 个解决方案
#1
466
I believe you can do this:
我相信你可以做到:
gem "foo", :path => "/path/to/foo"
#2
196
In addition to specifying the path (as Jimmy mentioned) you can also force Bundler to use a local gem for your environment only by using the following configuration option:
除了指定路径(如Jimmy提到的),您还可以通过以下配置选项强制Bundler为您的环境使用本地gem:
$ bundle config local.GEM_NAME /path/to/local/git/repository
This is extremely helpful if you're developing two gems or a gem and a rails app side-by-side.
如果您同时开发两个gems或gem和rails应用程序,这将非常有用。
Note though, that this only works when you're already using git for your dependency, for example:
但是请注意,这只在您已经在使用git作为依赖项时有效,例如:
# In Gemfile
gem 'rack', :github => 'rack/rack', :branch => 'master'
# In your terminal
$ bundle config local.rack ~/Work/git/rack
As seen on the docs.
就像在文档中看到的。
#3
27
You can also reference a local gem with git if you happen to be working on it.
如果您碰巧正在处理它,您还可以使用git引用本地gem。
gem 'foo',
:git => '/Path/to/local/git/repo',
:branch => 'my-feature-branch'
Then, if it changes I run
然后,如果它改变我运行。
bundle exec gem uninstall foo
bundle update foo
But I am not sure everyone needs to run these two steps.
但我不确定是否每个人都需要执行这两个步骤。
#4
16
In order to use local gem repository in a Rails project, follow the steps below:
为了在Rails项目中使用本地gem存储库,请遵循以下步骤:
-
Check if your gem folder is a git repository (the command is executed in the gem folder)
检查您的gem文件夹是否是git存储库(命令在gem文件夹中执行)
git rev-parse --is-inside-work-tree
-
Getting repository path (the command is executed in the gem folder)
获取存储库路径(在gem文件夹中执行命令)
git rev-parse --show-toplevel
-
Setting up a local override for the rails application
为rails应用程序设置一个本地覆盖。
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 point2
GEM_NAME是您的gem的名称,/path/to/local/git/repository是第2点命令的输出吗
-
In your application
Gemfile
add the following line:在您的应用程序Gemfile中添加以下一行:
gem 'GEM_NAME', :github => 'GEM_NAME/GEM_NAME', :branch => 'master'
-
Running
bundle install
should give something like this:运行bundle安装应该给出如下内容:
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 point2
在第2点,GEM_NAME是您的gem和/path/to/local/git/存储库的名称?
-
Finally, run
bundle list
, notgem list
and you should see something like this:最后,运行bundle list,而不是gem list,您应该看到如下内容:
GEM_NAME (0.0.1 5a68b88)
where
GEM_NAME
is the name of your gem宝石的名字在哪里
A few important cases I am observing using:
我正在观察的几个重要案例是:
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 - 看来RubyMine并没有将本地gem作为外部库来展示。关于这个bug的更多信息可以在这里和这里找到
- 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 - 当我在本地gem中更改某些内容时,为了在rails应用程序中加载,我应该停止/启动rails服务器
-
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 applicationGemfile
like this:如果我正在更改gem的版本,那么停止/启动Rails服务器会给我一个错误。为了修复它,我在rails应用程序Gemfile中指定了gem版本,如下所示:
gem 'GEM_NAME', '0.0.2', :github => 'GEM_NAME/GEM_NAME', :branch => 'master'
#5
0
You can reference gems with source: source: 'https://source.com', git repository (:github => 'git/url')
and with local path :path => '.../path/gem_name'
.
You can learn more about Gemfiles and how to use them in this article.
您可以引用gems with source: source: https://source.com, git repository (:github => 'git/url'),以及local path:path => '…/path/gem_name'。在本文中,您可以了解关于Gemfiles的更多信息,以及如何使用它们。
#6
-2
If you want the branch too:
如果你也想要分行:
gem 'foo', path: "point/to/your/path", branch: "branch-name"
#1
466
I believe you can do this:
我相信你可以做到:
gem "foo", :path => "/path/to/foo"
#2
196
In addition to specifying the path (as Jimmy mentioned) you can also force Bundler to use a local gem for your environment only by using the following configuration option:
除了指定路径(如Jimmy提到的),您还可以通过以下配置选项强制Bundler为您的环境使用本地gem:
$ bundle config local.GEM_NAME /path/to/local/git/repository
This is extremely helpful if you're developing two gems or a gem and a rails app side-by-side.
如果您同时开发两个gems或gem和rails应用程序,这将非常有用。
Note though, that this only works when you're already using git for your dependency, for example:
但是请注意,这只在您已经在使用git作为依赖项时有效,例如:
# In Gemfile
gem 'rack', :github => 'rack/rack', :branch => 'master'
# In your terminal
$ bundle config local.rack ~/Work/git/rack
As seen on the docs.
就像在文档中看到的。
#3
27
You can also reference a local gem with git if you happen to be working on it.
如果您碰巧正在处理它,您还可以使用git引用本地gem。
gem 'foo',
:git => '/Path/to/local/git/repo',
:branch => 'my-feature-branch'
Then, if it changes I run
然后,如果它改变我运行。
bundle exec gem uninstall foo
bundle update foo
But I am not sure everyone needs to run these two steps.
但我不确定是否每个人都需要执行这两个步骤。
#4
16
In order to use local gem repository in a Rails project, follow the steps below:
为了在Rails项目中使用本地gem存储库,请遵循以下步骤:
-
Check if your gem folder is a git repository (the command is executed in the gem folder)
检查您的gem文件夹是否是git存储库(命令在gem文件夹中执行)
git rev-parse --is-inside-work-tree
-
Getting repository path (the command is executed in the gem folder)
获取存储库路径(在gem文件夹中执行命令)
git rev-parse --show-toplevel
-
Setting up a local override for the rails application
为rails应用程序设置一个本地覆盖。
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 point2
GEM_NAME是您的gem的名称,/path/to/local/git/repository是第2点命令的输出吗
-
In your application
Gemfile
add the following line:在您的应用程序Gemfile中添加以下一行:
gem 'GEM_NAME', :github => 'GEM_NAME/GEM_NAME', :branch => 'master'
-
Running
bundle install
should give something like this:运行bundle安装应该给出如下内容:
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 point2
在第2点,GEM_NAME是您的gem和/path/to/local/git/存储库的名称?
-
Finally, run
bundle list
, notgem list
and you should see something like this:最后,运行bundle list,而不是gem list,您应该看到如下内容:
GEM_NAME (0.0.1 5a68b88)
where
GEM_NAME
is the name of your gem宝石的名字在哪里
A few important cases I am observing using:
我正在观察的几个重要案例是:
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 - 看来RubyMine并没有将本地gem作为外部库来展示。关于这个bug的更多信息可以在这里和这里找到
- 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 - 当我在本地gem中更改某些内容时,为了在rails应用程序中加载,我应该停止/启动rails服务器
-
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 applicationGemfile
like this:如果我正在更改gem的版本,那么停止/启动Rails服务器会给我一个错误。为了修复它,我在rails应用程序Gemfile中指定了gem版本,如下所示:
gem 'GEM_NAME', '0.0.2', :github => 'GEM_NAME/GEM_NAME', :branch => 'master'
#5
0
You can reference gems with source: source: 'https://source.com', git repository (:github => 'git/url')
and with local path :path => '.../path/gem_name'
.
You can learn more about Gemfiles and how to use them in this article.
您可以引用gems with source: source: https://source.com, git repository (:github => 'git/url'),以及local path:path => '…/path/gem_name'。在本文中,您可以了解关于Gemfiles的更多信息,以及如何使用它们。
#6
-2
If you want the branch too:
如果你也想要分行:
gem 'foo', path: "point/to/your/path", branch: "branch-name"