Skip to content

Commit

Permalink
New adventures in dependency reloading
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@429 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Jan 16, 2005
1 parent 394cf21 commit ee014ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/fixtures.rb
Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions activesupport/lib/dependencies.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 9 additions & 15 deletions railties/lib/dispatcher.rb
Expand Up @@ -24,39 +24,33 @@
require 'breakpoint'

class Dispatcher

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)

begin
Breakpoint.activate_drb("druby://localhost:#{BREAKPOINT_SERVER_PORT}", nil, !defined?(FastCGI)) if defined?(BREAKPOINT_SERVER_PORT)

request = ActionController::CgiRequest.new(cgi, session_options)
response = ActionController::CgiResponse.new(cgi)

controller_name, module_name = controller_name(request.parameters), module_name(request.parameters)

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

0 comments on commit ee014ef

Please sign in to comment.