【问题标题】:Rails bundler change branch of gem depending on environmentRails bundler 根据环境更改 gem 的分支
【发布时间】:2018-08-21 03:23:56
【问题描述】:

我正在尝试根据 Rails 环境在我的 Gemfile.rb 中使用不同的分支。这可能吗?

我尝试了以下方法,但无论环境如何,分支始终是 branch_B:

branch = 'branch_A'
group :production do
  branch = 'branch_B'
end
gem 'gem_name', git:'git_url', branch: branch

【问题讨论】:

  • 你从哪里得到分支?以后要hard code吗?
  • 分支名称是硬编码的,我希望分支在生产环境中为 branch_B,在其他环境中为 branch_A。

标签: ruby-on-rails bundler gemfile


【解决方案1】:

看看有没有帮助

def branch
    if ENV["RAILS_ENV"] == "production"
        @branch = 'branch_B'
        puts "I'm in production"
    else
        @branch = 'branch_A'
        puts "I'm in development"
    end
end

gem 'sqlite3', branch: branch

在终端中,你必须运行

RAILS_ENV=development bundle

【讨论】:

  • 谢谢,我最终在 Gemfile 中做了类似的事情。我按照您的建议使用了环境变量来相应地设置分支。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-08
  • 2015-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多