LoginSignup
34
22

More than 5 years have passed since last update.

Rails 5.0.1 で rails new するとできる Gemfile の git_source ブロックの意味

Posted at

ブログに書いた話をこちらでも共有。


Rails 5.0.1 で rails new したときに作成される Gemfile の先頭に次のブロックが挿入されるようになっていました。

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

これの意味

Gemfile の中で :github オプションをつけた gem について、HTTPS 経由で GitHub から取得します。

git_sourceBundler で定義されているメソッド で、引数のオプション(ここでは :github)が付いた gem の取得先 URL をブロック内で指定できます。

やる理由

Bundler が持つ :github オプションは Git プロトコルで通信するのでセキュアでなく、さらに Bundler 1.13 以降は :github オプションを使っていると警告が出ます。公式ドキュメントでも :github オプションを使うのを避けるよう明記してあります。

このコードを入れておくと、HTTPS 経由で GitHub から gem を取得できるので警告が出ずにすみます。ちなみにデフォルトの Gemfile では web-console:github オプションを使っていますね。Bundler 2.0 ではこの点が対策されるようで、それまでの対処ということです。

入ったプルリクはこちらです。

参考資料

34
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
22