aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/kernel.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-11-21 07:29:44 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-11-21 07:29:44 +0000
commit9a77e2f2bed486189c6246bf346369b19e1ea21a (patch)
tree5b4da1c9a215b3e763df8c5bb13b21639dd0975a /activesupport/lib/active_support/core_ext/kernel.rb
parentd7924273014a183e86538f33f0f52ceade10cd46 (diff)
downloadrails-9a77e2f2bed486189c6246bf346369b19e1ea21a.tar.gz
rails-9a77e2f2bed486189c6246bf346369b19e1ea21a.tar.bz2
rails-9a77e2f2bed486189c6246bf346369b19e1ea21a.zip
r3240@asus: jeremy | 2005-11-20 23:22:34 -0800
Introduce enable_warnings counterpart to silence_warnings. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3134 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/kernel.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/kernel.rb41
1 files changed, 25 insertions, 16 deletions
diff --git a/activesupport/lib/active_support/core_ext/kernel.rb b/activesupport/lib/active_support/core_ext/kernel.rb
index b687af03f6..d722c306cd 100644
--- a/activesupport/lib/active_support/core_ext/kernel.rb
+++ b/activesupport/lib/active_support/core_ext/kernel.rb
@@ -29,6 +29,14 @@ class Object
$VERBOSE = old_verbose
end
+ # Sets $VERBOSE to true for the duration of the block and back to its original value afterwards.
+ def enable_warnings
+ old_verbose, $VERBOSE = $VERBOSE, true
+ yield
+ ensure
+ $VERBOSE = old_verbose
+ end
+
# Silences stderr for the duration of the block.
#
# silence_stderr do
@@ -54,26 +62,27 @@ class Object
rescue Errno::ENOENT => e
STDERR.puts "#$0: #{e}"
end
-
- # Method that requires a library, ensuring that rubygems is loaded
+
+ # Require a library with fallback to RubyGems. Warnings during library
+ # loading are silenced to increase signal/noise for application warnings.
def require_library_or_gem(library_name)
- begin
- require library_name
- rescue LoadError => cannot_require
- # 1. Requiring the module is unsuccessful, maybe it's a gem and nobody required rubygems yet. Try.
- begin
- require 'rubygems'
- rescue LoadError => rubygems_not_installed
- raise cannot_require
- end
- # 2. Rubygems is installed and loaded. Try to load the library again
+ silence_warnings do
begin
require library_name
- rescue LoadError => gem_not_installed
- raise cannot_require
+ rescue LoadError => cannot_require
+ # 1. Requiring the module is unsuccessful, maybe it's a gem and nobody required rubygems yet. Try.
+ begin
+ require 'rubygems'
+ rescue LoadError => rubygems_not_installed
+ raise cannot_require
+ end
+ # 2. Rubygems is installed and loaded. Try to load the library again
+ begin
+ require library_name
+ rescue LoadError => gem_not_installed
+ raise cannot_require
+ end
end
end
end
-
-
end