Changeset 3134
- Timestamp:
- 11/21/05 07:29:44 (3 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/kernel.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/dependencies.rb (modified) (2 diffs)
- trunk/activesupport/test/core_ext/kernel_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r3124 r3134 1 1 *SVN* 2 2 3 * Turn warnings on when loading a file if Dependencies.mechanism == :load. Common mistakes such as redefined methods will print warnings to stderr. [Jeremy Kemper]3 * Introduce enable_warnings counterpart to silence_warnings. Turn warnings on when loading a file if Dependencies.mechanism == :load. Common mistakes such as redefined methods will print warnings to stderr. [Jeremy Kemper] 4 4 5 5 * Add Symbol#to_proc, which allows for, e.g. [:foo, :bar].map(&:to_s). [Marcel Molina Jr.] trunk/activesupport/lib/active_support/core_ext/kernel.rb
r2902 r3134 30 30 end 31 31 32 # Sets $VERBOSE to true for the duration of the block and back to its original value afterwards. 33 def enable_warnings 34 old_verbose, $VERBOSE = $VERBOSE, true 35 yield 36 ensure 37 $VERBOSE = old_verbose 38 end 39 32 40 # Silences stderr for the duration of the block. 33 41 # … … 55 63 STDERR.puts "#$0: #{e}" 56 64 end 57 58 # Method that requires a library, ensuring that rubygems is loaded 65 66 # Require a library with fallback to RubyGems. Warnings during library 67 # loading are silenced to increase signal/noise for application warnings. 59 68 def require_library_or_gem(library_name) 60 begin 61 require library_name 62 rescue LoadError => cannot_require 63 # 1. Requiring the module is unsuccessful, maybe it's a gem and nobody required rubygems yet. Try. 64 begin 65 require 'rubygems' 66 rescue LoadError => rubygems_not_installed 67 raise cannot_require 68 end 69 # 2. Rubygems is installed and loaded. Try to load the library again 69 silence_warnings do 70 70 begin 71 71 require library_name 72 rescue LoadError => gem_not_installed 73 raise cannot_require 72 rescue LoadError => cannot_require 73 # 1. Requiring the module is unsuccessful, maybe it's a gem and nobody required rubygems yet. Try. 74 begin 75 require 'rubygems' 76 rescue LoadError => rubygems_not_installed 77 raise cannot_require 78 end 79 # 2. Rubygems is installed and loaded. Try to load the library again 80 begin 81 require library_name 82 rescue LoadError => gem_not_installed 83 raise cannot_require 84 end 74 85 end 75 86 end 76 87 end 77 78 79 88 end trunk/activesupport/lib/active_support/dependencies.rb
r3124 r3134 1 1 require File.dirname(__FILE__) + '/module_attribute_accessors' 2 2 require File.dirname(__FILE__) + '/core_ext/load_error' 3 require File.dirname(__FILE__) + '/core_ext/kernel' 3 4 4 5 module Dependencies #:nodoc: … … 38 39 file_name = "#{file_name}.rb" unless ! load? || file_name[-3..-1] == '.rb' 39 40 if load? 40 begin 41 original_verbosity, $VERBOSE = $VERBOSE, true 42 load file_name 43 ensure 44 $VERBOSE = original_verbosity 45 end 41 enable_warnings { load file_name } 46 42 else 47 43 require file_name trunk/activesupport/test/core_ext/kernel_test.rb
r3131 r3134 10 10 def test_silence_warnings_verbose_invariant 11 11 old_verbose = $VERBOSE 12 begin 13 silence_warnings { raise } 14 flunk 15 rescue 16 assert_equal old_verbose, $VERBOSE 17 end 12 silence_warnings { raise } 13 flunk 14 rescue 15 assert_equal old_verbose, $VERBOSE 18 16 end 19 20 def test_silence_warnings_with_return_value 21 assert_equal 1, silence_warnings { 1 } 17 18 19 def test_enable_warnings 20 enable_warnings { assert_equal true, $VERBOSE } 21 assert_equal 1234, enable_warnings { 1234 } 22 22 end 23 23 24 def test_enable_warnings_verbose_invariant 25 old_verbose = $VERBOSE 26 enable_warnings { raise } 27 flunk 28 rescue 29 assert_equal old_verbose, $VERBOSE 30 end 31 32 24 33 def test_silence_stderr 25 34 old_stderr_position = STDERR.tell … … 27 36 assert_equal old_stderr_position, STDERR.tell 28 37 end 29 38 30 39 def test_silence_stderr_with_return_value 31 40 assert_equal 1, silence_stderr { 1 }