which rails
>> /Users/Altech/.rvm/gems/ruby-1.9.3-p286/bin/railsload Gem.bin_path('railties', 'rails', version)
>> gem(railties)/bin/railsrequire "rails/cli"
>> gem(railties)/lib/rails/cli.rbrequire 'rails/script_rails_loader'; Rails::ScriptRailsLoader.exec_script_rails!
>> (app)/script/rails- ここでプロセスが(app)/script/railsに変身
- (app)/script/railsの
require File.expand_path('../../config/boot', __FILE__)
でBundlerチェックなど
require 'rails/commands'
>> gem(railties)/lib/rails/commands.rb- ここで引数処理. 今回は引数serverの場合を追う.
require 'rails/commands/server'
>> gem(railties)/lib/rails/commands/server.rbserver.rb
の冒頭でrequire 'action_dispatch'
。ActionPackのもの。action_dispatchでRackをrequireしている。Rails::Server << Rack::Server
Rails::Server.new.tap{ ... }
>> commands.rbに戻ってきて、tapの中身require APP_PATH
>> (app)/config/application.rbrails/all
して各種Railsコンポーネント読み込みBundler.require(*Rails.groups(:assets => %w(development test)))
でGemfileのrequireSampleApp::Application < Rails::Application
を定義
server.start
>> gem(railties)/lib/rails/commands/server.rb # tapに戻ってsuper
>> gem(rack)/lib/rack/server.rb # インスタンスメソッドの方wrapped_app
>>app
- appメソッドでconfig.ruの読み込み、Rails::Applicationを返す
build_app
で、appから返ってきたRails::Applicationを薄くラッピング)
server.run wrapped_app, options, &blk
でサーバー起動!
ここまででサーバー起動したので次回そこから。
def server
@_server ||= Rack::Handler.get(options[:server]) || Rack::Handler.default(options)
end