Fixed that auto reloading would some times not work or would reload the models...

Fixed that auto reloading would some times not work or would reload the models twice #475 [Tobias Luetke]


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@408 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 c755b29a
*SVN*
* Fixed that auto reloading would some times not work or would reload the models twice #475 [Tobias Luetke]
* Added rewrite rules to deal with caching to public/.htaccess
* Added the option to specify a controller name to "generate scaffold" and made the default controller name the plural form of the model.
......
......@@ -24,60 +24,70 @@
require 'breakpoint'
class Dispatcher
def self.dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS)
Breakpoint.activate_drb("druby://localhost:#{BREAKPOINT_SERVER_PORT}", nil, !defined?(FastCGI)) if defined?(BREAKPOINT_SERVER_PORT)
begin
request = ActionController::CgiRequest.new(cgi, session_options)
response = ActionController::CgiResponse.new(cgi)
controller_name, module_name = controller_name(request.parameters), module_name(request.parameters)
class <<self
def dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS)
Breakpoint.activate_drb("druby://localhost:#{BREAKPOINT_SERVER_PORT}", nil, !defined?(FastCGI)) if defined?(BREAKPOINT_SERVER_PORT)
require_dependency("application")
require_dependency(controller_path(controller_name, module_name))
begin
request = ActionController::CgiRequest.new(cgi, session_options)
response = ActionController::CgiResponse.new(cgi)
controller_name, module_name = controller_name(request.parameters), module_name(request.parameters)
controller_class(controller_name).process(request, response).out
rescue Object => exception
ActionController::Base.process_with_exception(request, response, exception).out
ensure
if Dependencies.mechanism == :load
ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses
Dependencies.reload rescue nil # Ignore out of order reloading errors for Controllers
remove_class_hierarchy(controller_class(controller_name), ActionController::Base)
require_dependency("application")
require_dependency(controller_path(controller_name, module_name))
reload_application rescue nil # Ignore out of order reloading errors for Controllers
controller_class(controller_name).process(request, response).out
rescue Object => exception
ActionController::Base.process_with_exception(request, response, exception).out
ensure
remove_class_hierarchy(controller_class(controller_name), ActionController::Base) if Dependencies.mechanism == :load
Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT)
end
Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT)
end
end
def self.controller_path(controller_name, module_name = nil)
if module_name
"#{module_name}/#{Inflector.underscore(controller_name)}_controller"
else
"#{Inflector.underscore(controller_name)}_controller"
end
end
def self.controller_class(controller_name)
Object.const_get(controller_class_name(controller_name))
end
def self.controller_class_name(controller_name)
"#{Inflector.camelize(controller_name)}Controller"
end
def self.controller_name(parameters)
parameters["controller"].gsub(/[^_a-zA-Z0-9]/, "").untaint
end
def self.module_name(parameters)
parameters["module"].gsub(/[^_a-zA-Z0-9]/, "").untaint if parameters["module"]
end
private
def reload_application
if Dependencies.mechanism == :load
ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses
Dependencies.reload
end
end
def self.remove_class_hierarchy(klass, until_superclass)
while klass
Object.send(:remove_const, "#{klass}".intern)
klass = (klass.superclass unless until_superclass == klass.superclass)
end
def controller_path(controller_name, module_name = nil)
if module_name
"#{module_name}/#{Inflector.underscore(controller_name)}_controller"
else
"#{Inflector.underscore(controller_name)}_controller"
end
end
def controller_class(controller_name)
Object.const_get(controller_class_name(controller_name))
end
def controller_class_name(controller_name)
"#{Inflector.camelize(controller_name)}Controller"
end
def controller_name(parameters)
parameters["controller"].gsub(/[^_a-zA-Z0-9]/, "").untaint
end
def module_name(parameters)
parameters["module"].gsub(/[^_a-zA-Z0-9]/, "").untaint if parameters["module"]
end
def remove_class_hierarchy(klass, until_superclass)
while klass
Object.send(:remove_const, "#{klass}".intern)
klass = (klass.superclass unless until_superclass == klass.superclass)
end
end
end
end
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册