Dispatches requests to the appropriate controller and takes care of reloading the app after each request when Dependencies.load? is true.

Methods
Included Modules
Public Class methods
define_dispatcher_callbacks(cache_classes)
    # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 8
 8:       def define_dispatcher_callbacks(cache_classes)
 9:         unless cache_classes
10:           # Development mode callbacks
11:           before_dispatch :reload_application
12:           after_dispatch :cleanup_application
13:         end
14: 
15:         # Common callbacks
16:         to_prepare :load_application_controller do
17:           begin
18:             require_dependency 'application' unless defined?(::ApplicationController)
19:           rescue LoadError => error
20:             raise unless error.message =~ /application\.rb/
21:           end
22:         end
23: 
24:         if defined?(ActiveRecord)
25:           after_dispatch :checkin_connections
26:           to_prepare(:activerecord_instantiate_observers) { ActiveRecord::Base.instantiate_observers }
27:         end
28: 
29:         after_dispatch :flush_logger if Base.logger && Base.logger.respond_to?(:flush)
30: 
31:         to_prepare do
32:           I18n.reload!
33:         end
34:       end
dispatch(cgi = nil, session_options = CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout)

Backward-compatible class method takes CGI-specific args. Deprecated in favor of Dispatcher.new(output, request, response).dispatch.

    # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 38
38:       def dispatch(cgi = nil, session_options = CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout)
39:         new(output).dispatch_cgi(cgi, session_options)
40:       end
failsafe_response(fallback_output, status, originating_exception = nil) {|| ...}

If the block raises, send status code as a last-ditch response.

    # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 57
57:       def failsafe_response(fallback_output, status, originating_exception = nil)
58:         yield
59:       rescue Exception => exception
60:         begin
61:           log_failsafe_exception(status, originating_exception || exception)
62:           body = failsafe_response_body(status)
63:           fallback_output.write "Status: #{status}\r\nContent-Type: text/html\r\n\r\n#{body}"
64:           nil
65:         rescue Exception => failsafe_error # Logger or IO errors
66:           $stderr.puts "Error during failsafe response: #{failsafe_error}"
67:           $stderr.puts "(originally #{originating_exception})" if originating_exception
68:         end
69:       end
new(output = $stdout, request = nil, response = nil)
     # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 103
103:     def initialize(output = $stdout, request = nil, response = nil)
104:       @output, @request, @response = output, request, response
105:     end
to_prepare(identifier = nil, &block)

Add a preparation callback. Preparation callbacks are run before every request in development mode, and before the first request in production mode.

An optional identifier may be supplied for the callback. If provided, to_prepare may be called again with the same identifier to replace the existing callback. Passing an identifier is a suggested practice if the code adding a preparation block may be reloaded.

    # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 50
50:       def to_prepare(identifier = nil, &block)
51:         @prepare_dispatch_callbacks ||= ActiveSupport::Callbacks::CallbackChain.new
52:         callback = ActiveSupport::Callbacks::Callback.new(:prepare_dispatch, block, :identifier => identifier)
53:         @prepare_dispatch_callbacks.replace_or_append!(callback)
54:       end
Public Instance methods
call(env)
     # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 138
138:     def call(env)
139:       @request = RackRequest.new(env)
140:       @response = RackResponse.new(@request)
141:       dispatch
142:     end
checkin_connections()
     # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 174
174:     def checkin_connections
175:       # Don't return connection (and peform implicit rollback) if this request is a part of integration test
176:       return if test_request?
177:       ActiveRecord::Base.clear_active_connections!
178:     end
cleanup_application()

Cleanup the application by clearing out loaded classes so they can be reloaded on the next request without restarting the server.

     # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 155
155:     def cleanup_application
156:       ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
157:       ActiveSupport::Dependencies.clear
158:       ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
159:     end
dispatch()
     # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 118
118:     def dispatch
119:       if ActionController::Base.allow_concurrency
120:         dispatch_unlocked
121:       else
122:         @@guard.synchronize do
123:           dispatch_unlocked
124:         end
125:       end
126:     end
dispatch_cgi(cgi, session_options)
     # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 128
128:     def dispatch_cgi(cgi, session_options)
129:       if cgi ||= self.class.failsafe_response(@output, '400 Bad Request') { CGI.new }
130:         @request = CgiRequest.new(cgi, session_options)
131:         @response = CgiResponse.new(cgi)
132:         dispatch
133:       end
134:     rescue Exception => exception
135:       failsafe_rescue exception
136:     end
dispatch_unlocked()
     # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 107
107:     def dispatch_unlocked
108:       begin
109:         run_callbacks :before_dispatch
110:         handle_request
111:       rescue Exception => exception
112:         failsafe_rescue exception
113:       ensure
114:         run_callbacks :after_dispatch, :enumerator => :reverse_each
115:       end
116:     end
flush_logger()
     # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 161
161:     def flush_logger
162:       Base.logger.flush
163:     end
mark_as_test_request!()
     # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 165
165:     def mark_as_test_request!
166:       @test_request = true
167:       self
168:     end
reload_application()
     # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 144
144:     def reload_application
145:       # Run prepare callbacks before every request in development mode
146:       run_callbacks :prepare_dispatch
147: 
148:       Routing::Routes.reload
149:       ActionController::Base.view_paths.reload!
150:       ActionView::Helpers::AssetTagHelper::AssetTag::Cache.clear
151:     end
test_request?()
     # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 170
170:     def test_request?
171:       @test_request
172:     end
Protected Instance methods
failsafe_rescue(exception)
     # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 186
186:       def failsafe_rescue(exception)
187:         self.class.failsafe_response(@output, '500 Internal Server Error', exception) do
188:           if @controller ||= defined?(::ApplicationController) ? ::ApplicationController : Base
189:             @controller.process_with_exception(@request, @response, exception).out(@output)
190:           else
191:             raise exception
192:           end
193:         end
194:       end
handle_request()
     # File vendor/rails/actionpack/lib/action_controller/dispatcher.rb, line 181
181:       def handle_request
182:         @controller = Routing::Routes.recognize(@request)
183:         @controller.process(@request, @response).out(@output)
184:       end