aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2005-10-08 07:48:37 +0000
committerMarcel Molina <marcel@vernix.org>2005-10-08 07:48:37 +0000
commit80cd2f664527607e901a4e114098c5dc63587e3b (patch)
tree3a164006471d037e81c6c10c0172d38d1b73a826 /activesupport/lib
parent60a60f979835992792feb6d3f78eb5f14350adb2 (diff)
downloadrails-80cd2f664527607e901a4e114098c5dc63587e3b.tar.gz
rails-80cd2f664527607e901a4e114098c5dc63587e3b.tar.bz2
rails-80cd2f664527607e901a4e114098c5dc63587e3b.zip
Move require_library_or_gem out of AR's abstract_adapter and into ActiveSupport. closes #1992
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2490 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/kernel.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/kernel.rb b/activesupport/lib/active_support/core_ext/kernel.rb
index 54979c1a1a..168c9cddd3 100644
--- a/activesupport/lib/active_support/core_ext/kernel.rb
+++ b/activesupport/lib/active_support/core_ext/kernel.rb
@@ -28,4 +28,26 @@ module Kernel
ensure
$VERBOSE = old_verbose
end
+
+ # Method that requires a library, ensuring that rubygems is loaded
+ 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
+ begin
+ require library_name
+ rescue LoadError => gem_not_installed
+ raise cannot_require
+ end
+ end
+ end
+
+
end