aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/lib/dependencies.rb18
-rw-r--r--railties/lib/dispatcher.rb27
2 files changed, 10 insertions, 35 deletions
diff --git a/activesupport/lib/dependencies.rb b/activesupport/lib/dependencies.rb
index 90b3dea5d5..3ceec71873 100644
--- a/activesupport/lib/dependencies.rb
+++ b/activesupport/lib/dependencies.rb
@@ -18,8 +18,8 @@ module Dependencies
loaded << file_name
begin
require_or_load(file_name)
- rescue LoadError
- raise unless swallow_load_errors
+ rescue Object => e
+ raise ScriptError, "#{e.message}" unless e.is_a?(LoadError) && swallow_load_errors
end
end
end
@@ -32,18 +32,8 @@ module Dependencies
self.loaded = [ ]
end
- def reload
- loaded.each do |file_name|
- begin
- silence_warnings { load("#{file_name}.rb") }
- rescue LoadError
- # We don't care if the file was removed now
- end
- end
- end
-
def require_or_load(file_name)
- mechanism == :load ? silence_warnings { load("#{file_name}.rb") } : require(file_name)
+ load? ? load("#{file_name}.rb") : require(file_name)
end
end
@@ -57,7 +47,7 @@ class Object #:nodoc:
# require_association when using single-table inheritance.
def const_missing(class_id)
begin
- require_dependency(Inflector.underscore(Inflector.demodulize(class_id.to_s)))
+ require_or_load(class_id.to_s.demodulize.underscore)
if Object.const_defined?(class_id) then return Object.const_get(class_id) else raise LoadError end
rescue LoadError
raise NameError, "uninitialized constant #{class_id}"
diff --git a/railties/lib/dispatcher.rb b/railties/lib/dispatcher.rb
index 3fb593bd9d..84dff75024 100644
--- a/railties/lib/dispatcher.rb
+++ b/railties/lib/dispatcher.rb
@@ -34,8 +34,6 @@ class Dispatcher
controller_name, module_name = controller_name(request.parameters), module_name(request.parameters)
- reload_models
-
require_or_load("application")
require_or_load(controller_path(controller_name, module_name))
@@ -43,23 +41,17 @@ class Dispatcher
rescue Object => exception
ActionController::Base.process_with_exception(request, response, exception).out
ensure
- remove_controllers(controller_name)
+ reset_application if Dependencies.load?
Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT)
end
end
private
- def reload_models
- if Dependencies.load?
- ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses
- Dependencies.reload
- end
- end
-
- def remove_controllers(controller_name)
- if Dependencies.load? && defined?(ApplicationController)
- remove_class_hierarchy(controller_class(controller_name), ActionController::Base)
- end
+ def reset_application
+ Dependencies.clear
+ ActiveRecord::Base.remove_subclasses
+ ActiveRecord::Observer.remove_subclasses
+ ActionController::Base.remove_subclasses
end
def controller_path(controller_name, module_name = nil)
@@ -85,12 +77,5 @@ class Dispatcher
def module_name(parameters)
parameters["module"].downcase.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