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

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

railstutorial.jp

  • 前回の続き見ていきます

 

1章続き rails new 何やってんの?

  • Rails::Command.invoke を読む
30: def invoke(full_namespace, args = [], **config)
=> 31:   namespace = full_namespace = full_namespace.to_s
32:
33: if char = namespace =~ /:(\w+)$/
34:   command_name, namespace = $1, namespace.slice(0, char)
35: else
36:   command_name = namespace
37: end
38:
39: command_name, namespace = "help", "help" if command_name.blank? || HELP_MAPPINGS.include?(command_name)
40: command_name, namespace = "version", "version" if %w( -v --version ).include?(command_name)
41:
42: command = find_by_namespace(namespace, command_name)
43:   if command && command.all_commands[command_name]
44:     command.perform(command_name, args, config)
45:   else
46:     find_by_namespace("rake").perform(full_namespace, args, config)
47:   end
48: end
  • 42行目   - Rails::Command.invokecommand には Rails::Command::ApplicationCommand が入る
  • command.all_commands
 {"help"=>#<struct Thor::Command name="help", description="", long_description=nil, usage="", options={}, ancestor_name=nil>,
 "application"=>#<struct Thor::Command name="application", description="", long_description=nil, usage="", options={}, ancestor_name=nil>}

  - command.perform(command_name, args, config) - rails/command/base.rb の perform を読む

    58: def perform(command, args, config) # :nodoc:
 => 59:   if Rails::Command::HELP_MAPPINGS.include?(args.first)
    60:     command, args = "help", []
    61:   end
    62: 
    63:   dispatch(command, args.dup, nil, config)
    64: end
  • args が help系でなければ dispatch(command, args.dup, nil, config)

    • help系 => ["-h", "-?", "--help"]
  • perform は行うという意味らしい

  • 短いけど今回は終わり。更新頻度を上げること目標に・・・

  • 次は dispatch 読んでいきます。