From c0466603288252a5db8a4d8cf0ca193004a542ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 16:23:50 +0100 Subject: Give hooks the flexibility to choose the type of callback. --- railties/lib/rails/application.rb | 16 +++++++++------- railties/lib/rails/application/finisher.rb | 10 ++++------ 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 2648476d6d..acbfd7078b 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -115,19 +115,21 @@ module Rails # A plugin may override this if they desire to provide a more # exquisite route reloading. # :api: plugin - def routes_reloader_hook - app = self - lambda { app.routes_reloader.execute_if_updated } + def set_routes_reloader_hook + reloader = routes_reloader + hook = lambda { reloader.execute_if_updated } + hook.call + ActionDispatch::Reloader.to_prepare(&hook) end - # An app reloader hook that is used to setup to_cleanup callbacks. + # An app dependencies hook that is used to setup to_cleanup callbacks. # A plugin may override this if they desire to provide a more exquisite app reloading. # :api: plugin - def app_reloader_hook - lambda { + def set_dependencies_hook + ActionDispatch::Reloader.to_cleanup do ActiveSupport::DescendantsTracker.clear ActiveSupport::Dependencies.clear - } + end end # Initialize the application passing the given group. By default, the diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 9c25e05ee5..17e7aa0f28 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -66,16 +66,14 @@ module Rails # Set app reload just after the finisher hook to ensure # paths added in the hook are still loaded. - initializer :set_clear_dependencies_hook, :group => :all do |app| - ActionDispatch::Reloader.to_cleanup(&app.app_reloader_hook) + initializer :set_dependencies_hook, :group => :all do |app| + app.set_dependencies_hook end # Set app reload just after the finisher hook to ensure # routes added in the hook are still loaded. - initializer :set_routes_reloader do |app| - reloader = app.routes_reloader_hook - reloader.call - ActionDispatch::Reloader.to_prepare(&reloader) + initializer :set_routes_reloader_hook do |app| + app.set_routes_reloader_hook end # Disable dependency loading during request cycle -- cgit v1.2.3