Rails チュートリアル 1章 勉強メモ10

Rails チュートリアルの勉強メモ

railstutorial.jp

  • 前回は rails new を追ってみた

bundle install 読んでみる

まずは bundle を探す

$ which bundle
$HOME/.rbenv/shims/bundle

mir3636.hatenablog.com

shims 以下のファイルは1章 勉強メモ1で見た通り全て同じ

- $HOME/.rbenv/versions/2.6.2/bin/bundle

require 'rubygems'

version = ">= 0.a"

str = ARGV.first
if str
  str = str.b[/\A_(.*)_\z/, 1]
  if str and Gem::Version.correct?(str)
    version = str
    ARGV.shift
  end
end

if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('bundler', 'bundle', version)
else
gem "bundler", version
load Gem.bin_path("bundler", "bundle", version)
end
  • .rbenv の下も同じものだったのか(生成してるならそうか

exe/bundle

  • コードを追っていくと gems以下のbundlerの exe/bundle に入った
    22: Bundler.with_friendly_errors do
    23:   require "bundler/cli"
    24: 
    25:   # Allow any command to use --help flag to show help for that command
 => 26:   help_flags = %w[--help -h]
    27:   help_flag_used = ARGV.any? {|a| help_flags.include? a }
    28:   args = help_flag_used ? Bundler::CLI.reformatted_help_args(ARGV) : ARGV
    29: 
    30:   Bundler::CLI.start(args, :debug => true)
    31: end
  • help チェックして Bundler::CLI.start へ
- bundler/cli.rb @ line 18 Bundler::CLI.start:

    17: def self.start(*)
 => 18:   super
    19: rescue Exception => e
    20:   Bundler.ui = UI::Shell.new
    21:   raise e
    22: ensure
    23:   Bundler::SharedHelpers.print_major_deprecations!
    24: end
- thor/base.rb @ line 466 Bundler::Thor::Base::ClassMethods#start:

    464: def start(given_args = ARGV, config = {})
    465:   config[:shell] ||= Bundler::Thor::Base.shell.new
 => 466:   dispatch(nil, given_args.dup, nil, config)
    467: rescue Bundler::Thor::Error => e
    468:   config[:debug] || ENV["THOR_DEBUG"] == "1" ? (raise e) : config[:shell].error(e.message)
    469:   exit(1) if exit_on_failure?
    470: rescue Errno::EPIPE
    471:   # This happens if a thor command is piped to something like `head`,
    472:   # which closes the pipe when it's done reading. This will also
    473:   # mean that if the pipe is closed, further unnecessary
    474:   # computation will not occur.
    475:   exit(0)
    476: end
  • cli gem の thor の start から dispach へ
bundler/cli.rb @ line 27 Bundler::CLI.dispatch:

    26: def self.dispatch(*)
 => 27:   super do |i|
    28:     i.send(:print_command)
    29:     i.send(:warn_on_outdated_bundler)
    30:   end
    31: end

Rails チュートリアル 1章 勉強メモ6 - mir3636のブログ

でも見た dispach へ - dispach から instance.invoke_command(command, trailing || []) - invoke_command -> run -> send(install) を経て bundler の install メソッドへ

bundler/cli.rb @ line 233 Bundler::CLI#install:

    232: def install
 => 233:   SharedHelpers.major_deprecation(2, "The `--force` option has been renamed to `--redownload`") if ARGV.include?("--force")
    234:   require "bundler/cli/install"
    235:   Bundler.settings.temporary(:no_install => false) do
    236:     Install.new(options.dup).run
    237:   end
    238: end
  • install までたどり着いてので一旦終了