gpt4 book ai didi

ruby-on-rails - 为开发/测试和生产指定相同的 gem 两次,但路径不同

转载 作者:数据小太阳 更新时间:2023-10-29 07:06:39 25 4
gpt4 key购买 nike

有时您会制作特定于项目的 gem。这有助于将一些“责任”从主 Rails 应用程序中抽象出来并转移到一个更加模块化的地方。

gem 将位于您应用程序的此处:

gem 'example_gem', path: './example_gem'

你捆绑,一切都很好。现在,您 git init gem 并将其存储在 github 上它自己的 repo 中。您尝试这样做以使其对开发人员友好:

group :development, :test do
gem 'example_gem', path: './example_gem'
end

group :production do
gem 'example_gem', github: 'company/example_gem'
end

您因增加了工作流程而为自己鼓掌,但在运行 bundle 之后您会得到:

Your Gemfile lists the gem example_gem (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
You cannot specify the same gem twice coming from different sources.
You specified that example_gem (>= 0) should come from source at ./example_gem and git://github.com/company/example_gem.git

这里的工作流程是能够在开发中编辑 gem,完成后,提交这些更改并将它们推送到 Github。但是,在开发过程中,您不希望只为了看到一个小的变化就必须在主应用程序上执行 git commit、git push 和 bundle 更新。

有谁知道解决这个问题的更好方法吗?

最佳答案

是的,有一个更好的方法:首先,在所有环境中将 gem 作为 git gem

gem :example_gem, :git => 'git@github.com:foo/example_gem', :branch => :master #you need to set a branch

然后在您应用的文件夹中运行

bundle config --local local.example_gem /path/to/gem

这将编辑 .bundle/config 以设置此选项(确保此文件未 checkin 源代码管理!)并告诉 bundler 从该路径获取 gem。

当您要推送提交时,您必须小心一点:如果您的应用程序依赖于尚未提交的对 gem 的更改,那么很明显事情会崩溃。此外,当您提交示例 gem 的存储库时,rails 应用程序的 Gemfile.lock 将得到更新。如果你推送一个 Gemfile.lock 引用一个只存在于你的 example_gem 存储库副本中的提交,那么其他用户将被卡住。

关于ruby-on-rails - 为开发/测试和生产指定相同的 gem 两次,但路径不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24565817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com