From ee014ef95ae9746b4228f3bc7c85ac0df28ba1df Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 16 Jan 2005 17:50:36 +0000 Subject: [PATCH] New adventures in dependency reloading git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@429 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/fixtures.rb | 2 +- activesupport/lib/dependencies.rb | 16 ++++----------- railties/lib/dispatcher.rb | 24 ++++++++-------------- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 1db5d29bd7d53..3422ebcc36356 100755 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -158,7 +158,7 @@ def self.create_fixtures(fixtures_directory, *table_names) ActiveRecord::Base.logger.level = Logger::ERROR fixtures = table_names.flatten.map do |table_name| - Fixtures.new(connection, table_name.to_s, File.join(fixtures_directory, table_name.to_s)) + Fixtures.new(connection, File.split(table_name.to_s).last, File.join(fixtures_directory, table_name.to_s)) end connection.transaction do diff --git a/activesupport/lib/dependencies.rb b/activesupport/lib/dependencies.rb index 1452b63a77a9a..9ef1c251bcf9c 100644 --- a/activesupport/lib/dependencies.rb +++ b/activesupport/lib/dependencies.rb @@ -13,6 +13,8 @@ def depend_on(file_name, swallow_load_errors = false) if !loaded.include?(file_name) loaded << file_name + STDERR << "Loaded: #{file_name}\n" + begin require_or_load(file_name) rescue LoadError @@ -26,19 +28,9 @@ def associate_with(file_name) end def reload - old_loaded = loaded + reloading = loaded.dup clear - - old_loaded.each do |file_name| - next if loaded.include?(file_name) - - begin - silence_warnings { load("#{file_name}.rb") } - loaded << file_name - rescue LoadError - # The association didn't reside in its own file, so we assume it was required by other means - end - end + reloading.each { |file_name| depend_on(file_name, true) } end def clear diff --git a/railties/lib/dispatcher.rb b/railties/lib/dispatcher.rb index 81c1ed9cb368c..05cbab42655d2 100644 --- a/railties/lib/dispatcher.rb +++ b/railties/lib/dispatcher.rb @@ -24,13 +24,11 @@ require 'breakpoint' class Dispatcher - class < exception ActionController::Base.process_with_exception(request, response, exception).out - ensure - remove_class_hierarchy(controller_class(controller_name), ActionController::Base) if Dependencies.mechanism == :load + ensure + reset_application(controller_name) if Dependencies.mechanism == :load Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT) end end private - - def reload_application - if Dependencies.mechanism == :load - ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses - Dependencies.reload - end + def reset_application(controller_name) + ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses + Dependencies.clear + remove_class_hierarchy(controller_class(controller_name), ApplicationController) end def controller_path(controller_name, module_name = nil)