Changeset 5464
- Timestamp:
- 11/07/06 20:45:36 (2 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/dependencies.rb (modified) (3 diffs)
- trunk/activesupport/test/dependencies_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r5432 r5464 1 1 *SVN* 2 3 * Update dependencies to delete partially loaded constants. [Nicholas Seckar] 2 4 3 5 * Fix unicode JSON regexp for Onigurama compatibility. #6494 [whitley] trunk/activesupport/lib/active_support/dependencies.rb
r5386 r5464 235 235 end 236 236 237 raise ArgumentError, " Expected#{from_mod} is not missing constant #{const_name}!" if from_mod.const_defined?(const_name)237 raise ArgumentError, "#{from_mod} is not missing constant #{const_name}!" if from_mod.const_defined?(const_name) 238 238 239 239 qualified_name = qualified_name_for from_mod, const_name … … 302 302 # block calls +new_constants_in+ again, then the constants defined within the 303 303 # inner call will not be reported in this one. 304 # 305 # If the provided block does not run to completion, and instead raises an 306 # exception, any new constants are regarded as being only partially defined 307 # and will be removed immediately. 304 308 def new_constants_in(*descs) 305 309 log_call(*descs) … … 329 333 constant_watch_stack.concat watch_frames 330 334 331 yield # Now yield to the code that is to define new constants. 332 333 # Find the new constants. 334 new_constants = watch_frames.collect do |mod_name, prior_constants| 335 # Module still doesn't exist? Treat it as if it has no constants. 336 next [] unless qualified_const_defined?(mod_name) 335 aborting = true 336 begin 337 yield # Now yield to the code that is to define new constants. 338 aborting = false 339 ensure 340 # Find the new constants. 341 new_constants = watch_frames.collect do |mod_name, prior_constants| 342 # Module still doesn't exist? Treat it as if it has no constants. 343 next [] unless qualified_const_defined?(mod_name) 344 345 mod = mod_name.constantize 346 next [] unless mod.is_a? Module 347 new_constants = mod.constants - prior_constants 348 349 # Make sure no other frames takes credit for these constants. 350 constant_watch_stack.each do |frame_name, constants| 351 constants.concat new_constants if frame_name == mod_name 352 end 353 354 new_constants.collect do |suffix| 355 mod_name == "Object" ? suffix : "#{mod_name}::#{suffix}" 356 end 357 end.flatten 337 358 338 mod = mod_name.constantize 339 next [] unless mod.is_a? Module 340 new_constants = mod.constants - prior_constants 359 log "New constants: #{new_constants * ', '}" 341 360 342 # Make sure no other frames takes credit for these constants. 343 constant_watch_stack.each do |frame_name, constants| 344 constants.concat new_constants if frame_name == mod_name 345 end 346 347 new_constants.collect do |suffix| 348 mod_name == "Object" ? suffix : "#{mod_name}::#{suffix}" 349 end 350 end.flatten 351 352 log "New constants: #{new_constants * ', '}" 361 if aborting 362 log "Error during loading, removing partially loaded constants " 363 new_constants.each { |name| remove_constant name } 364 new_constants.clear 365 end 366 end 367 353 368 return new_constants 354 369 ensure trunk/activesupport/test/dependencies_test.rb
r5463 r5464 642 642 end 643 643 end 644 644 645 ensure 645 646 Object.send(:remove_const, :RaisesNoMethodError) if defined?(::RaisesNoMethodError) 646 647 end … … 654 655 end 655 656 end 656 657 658 ensure 657 659 Object.send(:remove_const, :RaisesNoMethodError) if defined?(::RaisesNoMethodError) 658 660 end … … 678 680 end 679 681 682 ensure 680 683 Object.send(:remove_const, :RaisesNameError) if defined?(::RaisesNameError) 681 684 end