Class: Dispatcher

Inherits:
Object show all
Defined in:
lib/dispatcher.rb

Overview

This class provides an interface for dispatching a CGI (or CGI-like) request to the appropriate controller and action. It also takes care of resetting the environment (when Dependencies.load? is true) after each request.

Class Method Summary collapse

Class Method Details

.dispatch(cgi = nil, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout) ⇒ Object

Dispatch the given CGI request, using the given session options, and emitting the output via the given output. If you dispatch with your own CGI object be sure to handle the exceptions it raises on multipart requests (EOFError and ArgumentError).



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dispatcher.rb', line 34

def dispatch(cgi = nil, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout)
  if cgi ||= new_cgi(output)
    request, response = ActionController::CgiRequest.new(cgi, session_options), ActionController::CgiResponse.new(cgi)
    prepare_application
    ActionController::Routing::Routes.recognize!(request).process(request, response).out(output)
  end
rescue Object => exception
  failsafe_response(output, '500 Internal Server Error', exception) do
    ActionController::Base.process_with_exception(request, response, exception).out(output)
  end
ensure
  # Do not give a failsafe response here.
  reset_after_dispatch
end

.reset_application!Object

Reset the application by clearing out loaded controllers, views, actions, mailers, and so forth. This allows them to be loaded again without having to restart the server (WEBrick, FastCGI, etc.).



52
53
54
55
56
# File 'lib/dispatcher.rb', line 52

def reset_application!
  Dependencies.clear
  ActiveRecord::Base.reset_subclasses
  Class.remove_class(*Reloadable.reloadable_classes)
end