Skip to content

Commit

Permalink
New approach to reloading that uses remove_const on ARs and AOs as we…
Browse files Browse the repository at this point in the history
…ll as ACs

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@507 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Jan 25, 2005
1 parent c37e8d3 commit ee662e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 35 deletions.
18 changes: 4 additions & 14 deletions activesupport/lib/dependencies.rb
Expand Up @@ -18,8 +18,8 @@ def depend_on(file_name, swallow_load_errors = false)
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
Expand All @@ -32,18 +32,8 @@ def clear
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

Expand All @@ -57,7 +47,7 @@ class << self
# 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}"
Expand Down
27 changes: 6 additions & 21 deletions railties/lib/dispatcher.rb
Expand Up @@ -34,32 +34,24 @@ def dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFA

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))

controller_class(controller_name).process(request, response).out
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)
Expand All @@ -85,12 +77,5 @@ def controller_name(parameters)
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

0 comments on commit ee662e9

Please sign in to comment.