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* *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 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. * Added the option to specify a controller name to "generate scaffold" and made the default controller name the plural form of the model.
......
...@@ -24,7 +24,10 @@ ...@@ -24,7 +24,10 @@
require 'breakpoint' require 'breakpoint'
class Dispatcher class Dispatcher
def self.dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS)
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) Breakpoint.activate_drb("druby://localhost:#{BREAKPOINT_SERVER_PORT}", nil, !defined?(FastCGI)) if defined?(BREAKPOINT_SERVER_PORT)
begin begin
...@@ -36,21 +39,27 @@ def self.dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest: ...@@ -36,21 +39,27 @@ def self.dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest:
require_dependency("application") require_dependency("application")
require_dependency(controller_path(controller_name, module_name)) 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 controller_class(controller_name).process(request, response).out
rescue Object => exception rescue Object => exception
ActionController::Base.process_with_exception(request, response, exception).out ActionController::Base.process_with_exception(request, response, exception).out
ensure ensure
if Dependencies.mechanism == :load remove_class_hierarchy(controller_class(controller_name), ActionController::Base) if Dependencies.mechanism == :load
ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT)
Dependencies.reload rescue nil # Ignore out of order reloading errors for Controllers end
remove_class_hierarchy(controller_class(controller_name), ActionController::Base)
end end
Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT) private
def reload_application
if Dependencies.mechanism == :load
ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses
Dependencies.reload
end end
end end
def self.controller_path(controller_name, module_name = nil) def controller_path(controller_name, module_name = nil)
if module_name if module_name
"#{module_name}/#{Inflector.underscore(controller_name)}_controller" "#{module_name}/#{Inflector.underscore(controller_name)}_controller"
else else
...@@ -58,26 +67,27 @@ def self.controller_path(controller_name, module_name = nil) ...@@ -58,26 +67,27 @@ def self.controller_path(controller_name, module_name = nil)
end end
end end
def self.controller_class(controller_name) def controller_class(controller_name)
Object.const_get(controller_class_name(controller_name)) Object.const_get(controller_class_name(controller_name))
end end
def self.controller_class_name(controller_name) def controller_class_name(controller_name)
"#{Inflector.camelize(controller_name)}Controller" "#{Inflector.camelize(controller_name)}Controller"
end end
def self.controller_name(parameters) def controller_name(parameters)
parameters["controller"].gsub(/[^_a-zA-Z0-9]/, "").untaint parameters["controller"].gsub(/[^_a-zA-Z0-9]/, "").untaint
end end
def self.module_name(parameters) def module_name(parameters)
parameters["module"].gsub(/[^_a-zA-Z0-9]/, "").untaint if parameters["module"] parameters["module"].gsub(/[^_a-zA-Z0-9]/, "").untaint if parameters["module"]
end end
def self.remove_class_hierarchy(klass, until_superclass) def remove_class_hierarchy(klass, until_superclass)
while klass while klass
Object.send(:remove_const, "#{klass}".intern) Object.send(:remove_const, "#{klass}".intern)
klass = (klass.superclass unless until_superclass == klass.superclass) klass = (klass.superclass unless until_superclass == klass.superclass)
end end
end 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.
先完成此消息的编辑!
想要评论请 注册