public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fix discrepancies with loading rails/init.rb from gems. [#324 state:resolved]
technoweenie (author)
Sun Jun 08 11:04:04 -0700 2008
commit  e1bd75a92285c29269270e708e49d7cd5fabac36
tree    cf1602958c09ae5d072da4d020f24eb439373726
parent  924244bf5cfb3d359fbc58d935d33adebf571fd6
...
1
2
3
4
5
6
...
1
2
 
3
4
5
0
@@ -1,6 +1,5 @@
0
 *Edge*
0
 
0
-
0
 * Wrapped Rails.env in StringQuestioneer so you can do Rails.env.development? [DHH]
0
 
0
 * Add the gem load paths before the framework is loaded, so certain gems like RedCloth and BlueCloth can be frozen.
...
23
24
25
 
 
 
 
26
27
28
 
29
30
31
...
23
24
25
26
27
28
29
30
31
 
32
33
34
35
0
@@ -23,9 +23,13 @@ module Rails
0
       @unpack_directory = nil
0
     end
0
 
0
+    def unpacked_paths
0
+      Dir[File.join(self.class.unpacked_path, "#{@name}-#{@version || "*"}")]
0
+    end
0
+
0
     def add_load_paths
0
       return if @loaded || @load_paths_added
0
-      unpacked_paths = Dir[File.join(self.class.unpacked_path, "#{@name}-#{@version || "*"}")]
0
+      unpacked_paths = self.unpacked_paths
0
       if unpacked_paths.empty?
0
         args = [@name]
0
         args << @requirement.to_s if @requirement
...
87
88
89
90
91
92
93
94
95
96
97
 
 
 
 
 
 
 
 
98
99
100
...
103
104
105
106
107
 
 
 
108
109
110
...
87
88
89
 
 
 
 
 
 
 
 
90
91
92
93
94
95
96
97
98
99
100
...
103
104
105
 
 
106
107
108
109
110
111
0
@@ -87,14 +87,14 @@ module Rails
0
       end
0
 
0
       def evaluate_init_rb(initializer)
0
-         if has_init_file?
0
-           silence_warnings do
0
-             # Allow plugins to reference the current configuration object
0
-             config = initializer.configuration
0
-             
0
-             eval(IO.read(init_path), binding, init_path)
0
-           end
0
-         end
0
+        if has_init_file?
0
+          silence_warnings do
0
+            # Allow plugins to reference the current configuration object
0
+            config = initializer.configuration
0
+            
0
+            eval(IO.read(init_path), binding, init_path)
0
+          end
0
+        end
0
       end               
0
   end
0
 
0
@@ -103,8 +103,9 @@ module Rails
0
   # to Dependencies.load_paths.
0
   class GemPlugin < Plugin
0
     # Initialize this plugin from a Gem::Specification.
0
-    def initialize(spec)
0
-      super(File.join(spec.full_gem_path))
0
+    def initialize(spec, gem)
0
+      directory = (gem.frozen? && gem.unpacked_paths.first) || File.join(spec.full_gem_path)
0
+      super(directory)
0
       @name = spec.name
0
     end
0
 
...
78
79
80
81
82
 
 
 
83
84
85
...
91
92
93
94
 
95
96
97
...
78
79
80
 
 
81
82
83
84
85
86
...
92
93
94
 
95
96
97
98
0
@@ -78,8 +78,9 @@ module Rails
0
     # a <tt>rails/init.rb</tt> file.
0
     class GemLocator < Locator
0
       def plugins
0
-        specs  = initializer.configuration.gems.map(&:specification)
0
-        specs += Gem.loaded_specs.values.select do |spec|
0
+        gem_index = initializer.configuration.gems.inject({}) { |memo, gem| memo.update gem.specification => gem }
0
+        specs     = gem_index.keys
0
+        specs    += Gem.loaded_specs.values.select do |spec|
0
           spec.loaded_from && # prune stubs
0
             File.exist?(File.join(spec.full_gem_path, "rails", "init.rb"))
0
         end
0
@@ -91,7 +92,7 @@ module Rails
0
         deps.add(*specs) unless specs.empty?
0
 
0
         deps.dependency_order.collect do |spec|
0
-          Rails::GemPlugin.new(spec)
0
+          Rails::GemPlugin.new(spec, gem_index[spec])
0
         end
0
       end
0
     end
...
94
95
96
97
 
98
99
100
...
94
95
96
 
97
98
99
100
0
@@ -94,7 +94,7 @@ uses_mocha "Plugin Loader Tests" do
0
 
0
     def test_should_add_plugin_load_paths_to_global_LOAD_PATH_array
0
       only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
0
-      stubbed_application_lib_index_in_LOAD_PATHS = 5
0
+      stubbed_application_lib_index_in_LOAD_PATHS = 4
0
       @loader.stubs(:application_lib_index).returns(stubbed_application_lib_index_in_LOAD_PATHS)
0
 
0
       @loader.add_plugin_load_paths

Comments