mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
New approach to reloading that uses remove_const on ARs and AOs as well as ACs
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@507 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
c37e8d365b
commit
ee662e9768
2 changed files with 10 additions and 35 deletions
|
@ -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}"
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue