rails s を読む
Omniauth読むはずが,Rackを理解したい気持ちになって(n回目)気づいたら Rails c
command を読んでた.
Guides rails/initialization.md
When one types a Rails command, invoke tries to lookup a command for the given namespace and executes the command if found.
railsコマンドを実行すると rails/command.rb がコマンド探して実行してくれる.
<command_namespace>_command.rb
の <command_namespace>Command#perform
を呼ぶっぽい.
def perform set_application_directory! prepare_restart Rails::Server.new(server_options).tap do |server| # Require application after server sets environment to propagate # the --environment option. require APP_PATH Dir.chdir(Rails.application.root) server.start end end
Rails::Server.new
して #start
を呼んでるだけ.
set_application_directory!
は config.ru
がないディレクトリでもよしなに動くようにしてる.rails/actions.rb
Rails::Server
のコンストラクタrails/server_command.rb で,PortやHostなどの設定をして(server_options
),それを使って Rack::Server
を初期化してる.
RailsServer#start
def start print_boot_information trap(:INT) { exit } create_tmp_directories setup_dev_caching log_to_stdout if options[:log_stdout] super ensure # The '-h' option calls exit before @options is set. # If we call 'options' with it unset, we get double help banners. puts "Exiting" unless @options && options[:daemonize] end
cacheの設定などして,Rack::Server#start
してる.
よだん
-p 3001
みたいな option は ServerCommand
Classが継承している Base
Class で Thor を継承することで実現してる.(rails/base.rb)