public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Make requiring gems optional.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#743 state:resolved]
sandofsky (author)
Fri Aug 01 17:01:10 -0700 2008
NZKoz (committer)
Mon Aug 04 05:53:21 -0700 2008
commit  61842d97c5269af8a36a33115f50543a155f1608
tree    6b08b69619f1a0aa9a727a5dfaeaff1e1dead69f
parent  82343859d568799a4151facbde1f8c711ecb7a3f
...
688
689
690
691
 
 
692
693
694
695
696
697
 
 
 
698
699
700
...
688
689
690
 
691
692
693
694
695
696
697
698
699
700
701
702
703
704
0
@@ -688,13 +688,17 @@ Run `rake gems:install` to install the missing gems.
0
     # You can add gems with the #gem method.
0
     attr_accessor :gems
0
 
0
-    # Adds a single Gem dependency to the rails application.
0
+    # Adds a single Gem dependency to the rails application. By default, it will require
0
+    # the library with the same name as the gem. Use :lib to specify a different name.
0
     #
0
     #   # gem 'aws-s3', '>= 0.4.0'
0
     #   # require 'aws/s3'
0
     #   config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
0
     #     :source => "http://code.whytheluckystiff.net"
0
     #
0
+    # To require a library be installed, but not attempt to load it, pass :lib => false
0
+    #
0
+    #   config.gem 'qrp', :version => '0.4.1', :lib => false
0
     def gem(name, options = {})
0
       @gems << Rails::GemDependency.new(name, options)
0
     end
...
58
59
60
61
 
62
63
64
...
58
59
60
 
61
62
63
64
0
@@ -58,7 +58,7 @@ module Rails
0
 
0
     def load
0
       return if @loaded || @load_paths_added == false
0
-      require(@lib || @name)
0
+      require(@lib || @name) unless @lib == false
0
       @loaded = true
0
     rescue LoadError
0
       puts $!.to_s
...
11
12
13
 
14
15
16
...
62
63
64
 
 
 
 
 
 
 
 
65
66
...
11
12
13
14
15
16
17
...
63
64
65
66
67
68
69
70
71
72
73
74
75
0
@@ -11,6 +11,7 @@ uses_mocha "Plugin Tests" do
0
       @gem_with_source  = Rails::GemDependency.new "hpricot", :source => "http://code.whytheluckystiff.net"
0
       @gem_with_version = Rails::GemDependency.new "hpricot", :version => "= 0.6"
0
       @gem_with_lib     = Rails::GemDependency.new "aws-s3", :lib => "aws/s3"
0
+      @gem_without_load  = Rails::GemDependency.new "hpricot", :lib => false
0
     end
0
 
0
     def test_configuration_adds_gem_dependency
0
@@ -62,5 +63,13 @@ uses_mocha "Plugin Tests" do
0
       @gem_with_lib.add_load_paths
0
       @gem_with_lib.load
0
     end
0
+
0
+    def test_gem_without_lib_loading
0
+      @gem_without_load.expects(:gem).with(@gem_without_load.name)
0
+      @gem_without_load.expects(:require).with(@gem_without_load.lib).never
0
+      @gem_without_load.add_load_paths
0
+      @gem_without_load.load
0
+    end
0
+
0
   end
0
 end

Comments