Dispatches requests to the appropriate controller and takes care of reloading the app after each request when Dependencies.load? is true.
- _call
- call
- cleanup_application
- define_dispatcher_callbacks
- dispatch
- dispatch
- dispatch_cgi
- flush_logger
- new
- reload_application
- run_prepare_callbacks
- to_prepare
[ show source ]
# File actionpack/lib/action_controller/dispatcher.rb, line 61
61: def cleanup_application
62: # Cleanup the application before processing the current request.
63: ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
64: ActiveSupport::Dependencies.clear
65: ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
66: end
[ show source ]
# File actionpack/lib/action_controller/dispatcher.rb, line 8
8: def define_dispatcher_callbacks(cache_classes)
9: @@cache_classes = cache_classes
10: unless cache_classes
11: ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
12: end
13:
14: if defined?(ActiveRecord)
15: to_prepare(:activerecord_instantiate_observers) { ActiveRecord::Base.instantiate_observers }
16: end
17:
18: after_dispatch :flush_logger if Base.logger && Base.logger.respond_to?(:flush)
19:
20: to_prepare do
21: I18n.reload!
22: end
23: end
DEPRECATE: Remove CGI support
[ show source ]
# File actionpack/lib/action_controller/dispatcher.rb, line 26
26: def dispatch(cgi = nil, session_options = CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout)
27: new(output).dispatch_cgi(cgi, session_options)
28: end
DEPRECATE: Remove arguments, since they are only used by CGI
[ show source ]
# File actionpack/lib/action_controller/dispatcher.rb, line 79
79: def initialize(output = $stdout, request = nil, response = nil)
80: @output = output
81: build_middleware_stack if @@cache_classes
82: end
[ show source ]
# File actionpack/lib/action_controller/dispatcher.rb, line 54
54: def reload_application
55: # Run prepare callbacks before every request in development mode
56: run_prepare_callbacks
57:
58: Routing::Routes.reload
59: end
[ show source ]
# File actionpack/lib/action_controller/dispatcher.rb, line 44
44: def run_prepare_callbacks
45: if defined?(Rails) && Rails.logger
46: logger = Rails.logger
47: else
48: logger = Logger.new($stderr)
49: end
50:
51: new(logger).send :run_callbacks, :prepare_dispatch
52: end
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.
[ show source ]
# File actionpack/lib/action_controller/dispatcher.rb, line 38
38: def to_prepare(identifier = nil, &block)
39: @prepare_dispatch_callbacks ||= ActiveSupport::Callbacks::CallbackChain.new
40: callback = ActiveSupport::Callbacks::Callback.new(:prepare_dispatch, block, :identifier => identifier)
41: @prepare_dispatch_callbacks.replace_or_append!(callback)
42: end
[ show source ]
# File actionpack/lib/action_controller/dispatcher.rb, line 119
119: def _call(env)
120: @env = env
121: dispatch
122: end
[ show source ]
# File actionpack/lib/action_controller/dispatcher.rb, line 104
104: def call(env)
105: if @@cache_classes
106: @app.call(env)
107: else
108: Reloader.run do
109: # When class reloading is turned on, we will want to rebuild the
110: # middleware stack every time we process a request. If we don't
111: # rebuild the middleware stack, then the stack may contain references
112: # to old classes metal classes, which will b0rk class reloading.
113: build_middleware_stack
114: @app.call(env)
115: end
116: end
117: end
[ show source ]
# File actionpack/lib/action_controller/dispatcher.rb, line 84
84: def dispatch
85: begin
86: run_callbacks :before_dispatch
87: Routing::Routes.call(@env)
88: rescue Exception => exception
89: if controller ||= (::ApplicationController rescue Base)
90: controller.call_with_exception(@env, exception).to_a
91: else
92: raise exception
93: end
94: ensure
95: run_callbacks :after_dispatch, :enumerator => :reverse_each
96: end
97: end
DEPRECATE: Remove CGI support
[ show source ]
# File actionpack/lib/action_controller/dispatcher.rb, line 100
100: def dispatch_cgi(cgi, session_options)
101: CGIHandler.dispatch_cgi(self, cgi, @output)
102: end
[ show source ]
# File actionpack/lib/action_controller/dispatcher.rb, line 124
124: def flush_logger
125: Base.logger.flush
126: end