Gemfile 内の新しいブロック「git_source(:github)」の意味 質問する

Gemfile 内の新しいブロック「git_source(:github)」の意味 質問する

最近、git リポジトリなしで新しい Rails 5 アプリを作成しました。自動生成された Gemfile には、これまで見たことのない新しいブロックが含まれています。

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

それはどういう意味ですか? すべての新しいアプリに必須ですか?

ベストアンサー1

これは、github からのソースが HTTPS ではなく HTTP 経由で読み込まれる可能性がある Bundler のバグに対する回避策であり、これにより中間者攻撃に対して脆弱になります。

git_sourceは、gem がパッケージではなく git リポジトリからダウンロードされるように使用できるソースを追加しますrubygems.org

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

次のように宣言すると、次のようになります。

gem 'foo_bar', :github => 'foo/bar'

Bundler は から gem をダウンロードしようとしますhttps://github.com/foo/bar.git

以来これを修正すると重大な変更となるこれは既存の Gemfile.lock を無効にするため、Bundler 2.x で修正されました。その時点で、この回避策を削除しても安全です。

おすすめ記事