lib/active_support/dependencies.rb in activesupport-3.0.1 vs lib/active_support/dependencies.rb in activesupport-3.0.2
- old
+ new
@@ -509,11 +509,16 @@
raise name_error
end
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
Reference.clear!
explicitly_unloadable_constants.each { |const| remove_constant const }
@@ -634,9 +639,10 @@
names = const.to_s.sub(/^::(Object)?/, 'Object::').split("::")
to_remove = names.pop
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
end