diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-09-11 04:58:27 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-09-11 04:58:27 +0000 |
commit | 3cf7a0a46037f32b95b5ffb358cb898233d5c5db (patch) | |
tree | 7a780b46eedb55daa761296005b163fdeea5f3e4 /activesupport | |
parent | 4b53e26ef612d870a01e646c45bcc4198ad3bd1a (diff) | |
download | rails-3cf7a0a46037f32b95b5ffb358cb898233d5c5db.tar.gz rails-3cf7a0a46037f32b95b5ffb358cb898233d5c5db.tar.bz2 rails-3cf7a0a46037f32b95b5ffb358cb898233d5c5db.zip |
Added Kernel#silence_warnings and puts it into use throughout the framework
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2179 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support.rb | 1 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/kernel.rb | 14 | ||||
-rw-r--r-- | activesupport/lib/active_support/misc.rb | 8 | ||||
-rw-r--r-- | activesupport/test/core_ext/kernel_test.rb (renamed from activesupport/test/misc_test.rb) | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/string_ext_test.rb | 3 | ||||
-rw-r--r-- | activesupport/test/dependencies_test.rb | 1 |
7 files changed, 20 insertions, 13 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index c4eed21534..acf9788285 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added Kernel#silence_warnings to turn off warnings temporarily for the passed block + * Added String#starts_with? and String#ends_with? #2118 [thijs@vandervossen.net] * Added easy extendability to the inflector through Inflector.inflections (using the Inflector::Inflections singleton class). Examples: diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index ba6945f3e5..7c7ae56e61 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -29,7 +29,6 @@ require 'active_support/inflector' require 'active_support/core_ext' require 'active_support/clean_logger' -require 'active_support/misc' require 'active_support/dependencies' require 'active_support/values/time_zone'
\ No newline at end of file diff --git a/activesupport/lib/active_support/core_ext/kernel.rb b/activesupport/lib/active_support/core_ext/kernel.rb index a2cb827d77..d4c3114488 100644 --- a/activesupport/lib/active_support/core_ext/kernel.rb +++ b/activesupport/lib/active_support/core_ext/kernel.rb @@ -14,4 +14,18 @@ module Kernel yield value end + + # Sets $VERBOSE to nil for the duration of the block and back to its original value afterwards. + # + # silence_warnings do + # noisy_call # no warning voiced + # end + # + # noisy_call # warning voiced + def silence_warnings + old_verbose, $VERBOSE = $VERBOSE, nil + yield + ensure + $VERBOSE = old_verbose + end end diff --git a/activesupport/lib/active_support/misc.rb b/activesupport/lib/active_support/misc.rb deleted file mode 100644 index 1ca00db1e7..0000000000 --- a/activesupport/lib/active_support/misc.rb +++ /dev/null @@ -1,8 +0,0 @@ -def silence_warnings - old_verbose, $VERBOSE = $VERBOSE, nil - begin - yield - ensure - $VERBOSE = old_verbose - end -end diff --git a/activesupport/test/misc_test.rb b/activesupport/test/core_ext/kernel_test.rb index cfd54c0ad0..d757362243 100644 --- a/activesupport/test/misc_test.rb +++ b/activesupport/test/core_ext/kernel_test.rb @@ -1,7 +1,7 @@ require 'test/unit' -require File.dirname(__FILE__) + '/../lib/active_support/misc' +require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/kernel' -class MiscTest < Test::Unit::TestCase +class KernelTest < Test::Unit::TestCase def test_silence_warnings silence_warnings { assert_nil $VERBOSE } assert_equal 1234, silence_warnings { 1234 } diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index c1c1918817..15189a75b1 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -1,6 +1,7 @@ require 'test/unit' +require 'date' require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/string' -require File.dirname(__FILE__) + '/../../lib/active_support/misc' +require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/kernel' silence_warnings do require File.dirname(__FILE__) + '/../inflector_test' diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 1af960ee36..a34fc0d323 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -1,6 +1,5 @@ require 'test/unit' $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib/active_support/' -require 'misc' require 'dependencies' class DependenciesTest < Test::Unit::TestCase |