Skip to content

Commit

Permalink
Fixed that auto reloading would some times not work or would reload t…
Browse files Browse the repository at this point in the history
…he models twice #475 [Tobias Luetke]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@408 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Jan 15, 2005
1 parent c755b29 commit 6c1fe63
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 50 deletions.
2 changes: 2 additions & 0 deletions railties/CHANGELOG
@@ -1,5 +1,7 @@
*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.
Expand Down
110 changes: 60 additions & 50 deletions railties/lib/dispatcher.rb
Expand Up @@ -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

0 comments on commit 6c1fe63

Please sign in to comment.