2004-11-23 20:04:44 -05:00
|
|
|
#--
|
|
|
|
# Copyright (c) 2004 David Heinemeier Hansson
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
# a copy of this software and associated documentation files (the
|
|
|
|
# "Software"), to deal in the Software without restriction, including
|
|
|
|
# without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
# permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
# the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be
|
|
|
|
# included in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
#++
|
|
|
|
|
2004-12-12 15:29:52 -05:00
|
|
|
require 'breakpoint'
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
class Dispatcher
|
2005-02-15 11:15:02 -05:00
|
|
|
class << self
|
2005-01-15 08:26:48 -05:00
|
|
|
def dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS)
|
|
|
|
begin
|
2005-02-20 12:20:10 -05:00
|
|
|
request, response = ActionController::CgiRequest.new(cgi, session_options), ActionController::CgiResponse.new(cgi)
|
2005-02-14 20:45:35 -05:00
|
|
|
prepare_application
|
|
|
|
ActionController::Routing::Routes.recognize!(request).process(request, response).out
|
2005-01-15 08:26:48 -05:00
|
|
|
rescue Object => exception
|
|
|
|
ActionController::Base.process_with_exception(request, response, exception).out
|
2005-01-16 12:50:36 -05:00
|
|
|
ensure
|
2005-02-14 20:45:35 -05:00
|
|
|
reset_application
|
2004-12-12 12:53:42 -05:00
|
|
|
end
|
2004-11-30 12:19:01 -05:00
|
|
|
end
|
2005-01-15 08:26:48 -05:00
|
|
|
|
|
|
|
private
|
2005-02-14 20:45:35 -05:00
|
|
|
def prepare_application
|
|
|
|
ActionController::Routing::Routes.reload if Dependencies.load?
|
2005-03-06 12:37:49 -05:00
|
|
|
Breakpoint.activate_drb("druby://localhost:#{BREAKPOINT_SERVER_PORT}", nil, !defined?(FastCGI)) if defined?(BREAKPOINT_SERVER_PORT) rescue nil
|
2005-02-20 08:47:57 -05:00
|
|
|
Controllers.const_load!(:ApplicationController, "application") unless Controllers.const_defined?(:ApplicationController)
|
2005-01-24 05:58:17 -05:00
|
|
|
end
|
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
def reset_application
|
|
|
|
if Dependencies.load?
|
2005-02-20 06:06:14 -05:00
|
|
|
Controllers.clear!
|
2005-02-14 20:45:35 -05:00
|
|
|
Dependencies.clear
|
|
|
|
Dependencies.remove_subclasses_for(ActiveRecord::Base, ActiveRecord::Observer, ActionController::Base)
|
2005-01-15 08:26:48 -05:00
|
|
|
end
|
2005-02-14 20:24:55 -05:00
|
|
|
|
2005-02-14 20:45:35 -05:00
|
|
|
Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT)
|
2005-01-15 08:26:48 -05:00
|
|
|
end
|
2005-01-02 13:32:56 -05:00
|
|
|
end
|
2005-02-20 12:20:10 -05:00
|
|
|
end
|