来自同一个github帐户的特定许多宝石

时间:2017-11-22 10:38:36

标签: ruby github bundler

pathsource一样,我想这样做:

git 'https://github.com/my_company', branch: 'rm_2422-rails5-upgrade' do
  gem 'foo'
  gem 'bar'
  # many more gems...
end

这样做的想法是使用foo分支获取带有https://github.com/my_company/foo.git的{​​{1}}宝石。

我可以从bundler docs看出这不是它的工作方式,我知道我能做到:

rm_2422-rails5-upgrade

但我有很多的宝石,需要从所述分支中提取。

我也看了git 'foo', git: 'https://github.com/my_company/foo.git', branch: 'rm_2422-rails5-upgrade' ,但这似乎也适用于这种情况。

2 个答案:

答案 0 :(得分:1)

您可以在git_source中定义新的Gemfile

git_source(:your_source_name) do |repo_name|
  repo_name = "company/#{repo_name}"
  "https://github.com/#{repo_name}.git"
end

然后使用它:

gem "gem_name", your_company: "gem_repo_name"

这是一个非常简单的示例,但您可以向块传递更多选项。我们使用此方法重新定义原始github源,以便能够为私有存储库传递身份验证令牌:

git_source(:github) do |(repo_name, auth_token)|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  auth_data = !!auth_token ? "#{auth_token}:x-oauth-basic@" : ""
  "https://#{auth_data}github.com/#{repo_name}.git"
end

更新:我找到了一种方法来做你需要的东西,但这是一个非常脏的黑客恕我直言。由于Gemfile是纯ruby文件,因此您可以在那里定义自己的函数:

def my_gem(name, *args)
  options = args.last.is_a?(Hash) ? args.pop.dup : {}
  version = args || [">= 0"]

  options[:branch] = "develop"

  gem(name, version, options)
end

然后使用它,而不是原始gem方法:

my_gem "gem_name"

答案 1 :(得分:0)

所以我用了一个解决方案:

['foo', 'bar'].each do |gem_name|
  gem gem_name, git: "https://github.com/my_company/#{gem_name}.git", branch: 'rm_2422-rails5-upgrade'
end
相关问题