aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/dependencies.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2010-09-01 14:12:06 +0100
committerXavier Noria <fxn@hashref.com>2010-09-01 22:32:41 +0200
commitf1966337fa744a1c62054120693072ebabe996a8 (patch)
tree4d5625e90ff2126d77e76916b203ff1c6278cb89 /activesupport/lib/active_support/dependencies.rb
parent2ce57fd0d9e2c1c1f787a0874f5292d5b2e9e539 (diff)
downloadrails-f1966337fa744a1c62054120693072ebabe996a8.tar.gz
rails-f1966337fa744a1c62054120693072ebabe996a8.tar.bz2
rails-f1966337fa744a1c62054120693072ebabe996a8.zip
Add before_remove_const callback to ActiveSupport::Dependencies.remove_unloadable_constants!
Signed-off-by: Xavier Noria <fxn@hashref.com>
Diffstat (limited to 'activesupport/lib/active_support/dependencies.rb')
-rw-r--r--activesupport/lib/active_support/dependencies.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index e6170b2daf..4bd97d3ee3 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -511,7 +511,12 @@ module ActiveSupport #:nodoc:
end
# Remove the constants that have been autoloaded, and those that have been
- # marked for unloading.
+ # marked for unloading. Before each constant is removed a callback is sent
+ # to its class/module if it implements +before_remove_const+.
+ #
+ # The callback implementation should be restricted to cleaning up caches, etc.
+ # as the enviroment will be in an inconsistent state, e.g. other constants
+ # may have already been unloaded and not accessible.
def remove_unloadable_constants!
autoloaded_constants.each { |const| remove_constant const }
autoloaded_constants.clear
@@ -636,6 +641,7 @@ module ActiveSupport #:nodoc:
parent = Inflector.constantize(names * '::')
log "removing constant #{const}"
+ constantize(const).before_remove_const if constantize(const).respond_to?(:before_remove_const)
parent.instance_eval { remove_const to_remove }
return true