Changeset 5303
- Timestamp:
- 10/14/06 20:29:05 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/dependencies.rb
r5302 r5303 39 39 self.autoloaded_constants = [] 40 40 41 # An array of constant names that need to be unloaded on every request. Used42 # to allow arbitrary constants to be marked for unloading.43 mattr_accessor :explicitly_unloadable_constants44 self.explicitly_unloadable_constants = []45 46 41 # Set to true to enable logging of const_missing and file loads 47 42 mattr_accessor :log_activity … … 66 61 log_call 67 62 loaded.clear 68 remove_ unloadable_constants!63 remove_autoloaded_constants! 69 64 end 70 65 … … 258 253 end 259 254 260 # Remove the constants that have been autoloaded, and those that have been 261 # marked for unloading. 262 def remove_unloadable_constants! 263 autoloaded_constants.each { |const| remove_constant const } 264 autoloaded_constants.clear 265 explicitly_unloadable_constants.each { |const| remove_constant const } 255 # Remove the constants that have been autoloaded. 256 def remove_autoloaded_constants! 257 until autoloaded_constants.empty? 258 const = autoloaded_constants.shift 259 next unless qualified_const_defined? const 260 names = const.split('::') 261 if names.size == 1 || names.first.empty? # It's under Object 262 parent = Object 263 else 264 parent = (names[0..-2] * '::').constantize 265 end 266 log "removing constant #{const}" 267 parent.send :remove_const, names.last 268 true 269 end 266 270 end 267 271 … … 271 275 return false unless qualified_const_defined? name 272 276 return autoloaded_constants.include?(name) 273 end274 275 # Will the provided constant descriptor be unloaded?276 def will_unload?(const_desc)277 autoloaded?(desc) ||278 explicitly_unloadable_constants.include?(const_desc.to_constant_name)279 end280 281 # Mark the provided constant name for unloading. This constant will be282 # unloaded on each request, not just the next one.283 def mark_for_unload(const_desc)284 name = const_desc.to_constant_name285 unless explicitly_unloadable_constants.include? name286 explicitly_unloadable_constants << name287 end288 277 end 289 278 … … 310 299 else raise TypeError, "Not a valid constant descriptor: #{desc.inspect}" 311 300 end 312 end313 314 def remove_constant(const)315 return false unless qualified_const_defined? const316 317 names = const.split('::')318 if names.size == 1 || names.first.empty? # It's under Object319 parent = Object320 else321 parent = (names[0..-2] * '::').constantize322 end323 324 log "removing constant #{const}"325 parent.send :remove_const, names.last326 return true327 301 end 328 302