Changeset 5302
- Timestamp:
- 10/14/06 20:27:29 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/dependencies.rb
r5053 r5302 39 39 self.autoloaded_constants = [] 40 40 41 # An array of constant names that need to be unloaded on every request. Used 42 # to allow arbitrary constants to be marked for unloading. 43 mattr_accessor :explicitly_unloadable_constants 44 self.explicitly_unloadable_constants = [] 45 41 46 # Set to true to enable logging of const_missing and file loads 42 47 mattr_accessor :log_activity … … 61 66 log_call 62 67 loaded.clear 63 remove_ autoloaded_constants!68 remove_unloadable_constants! 64 69 end 65 70 … … 253 258 end 254 259 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 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 } 270 266 end 271 267 … … 275 271 return false unless qualified_const_defined? name 276 272 return autoloaded_constants.include?(name) 273 end 274 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 end 280 281 # Mark the provided constant name for unloading. This constant will be 282 # unloaded on each request, not just the next one. 283 def mark_for_unload(const_desc) 284 name = const_desc.to_constant_name 285 unless explicitly_unloadable_constants.include? name 286 explicitly_unloadable_constants << name 287 end 277 288 end 278 289 … … 299 310 else raise TypeError, "Not a valid constant descriptor: #{desc.inspect}" 300 311 end 312 end 313 314 def remove_constant(const) 315 return false unless qualified_const_defined? const 316 317 names = const.split('::') 318 if names.size == 1 || names.first.empty? # It's under Object 319 parent = Object 320 else 321 parent = (names[0..-2] * '::').constantize 322 end 323 324 log "removing constant #{const}" 325 parent.send :remove_const, names.last 326 return true 301 327 end 302 328 trunk/activesupport/test/class_inheritable_attributes_test.rb
r5218 r5302 154 154 end 155 155 156 def test_array_inheritance 156 def test_array_inheritance_ 157 157 @klass.class_inheritable_accessor :a 158 158 @klass.a = {}