public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/technoweenie/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  faad1e32a8ab81890018ba89d191607778830cf0
tree    a7d07b839fae5004fac164cdceb9d76b9a568af2
parent  138adbf156905f5cc6669ba33dd94802c82514d9
...
1
2
 
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
9
0
@@ -1,5 +1,9 @@
0
 *Edge*
0
 
0
+* Fix discrepancies with loading rails/init.rb from gems.
0
+
0
+* Plugins check for the gem init path (rails/init.rb) before the standard plugin init path (init.rb)  [Jacek Becela]
0
+
0
 * Wrapped Rails.env in StringInquirer so you can do Rails.env.development? [DHH]
0
 
0
 * Fixed that RailsInfoController wasn't considering all requests local in development mode (Edgard Castro) [#310 state:resolved]
...
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
...
95
96
97
98
99
100
101
102
103
104
105
 
 
 
 
 
 
 
 
106
107
108
...
111
112
113
114
115
 
 
 
116
117
118
...
95
96
97
 
 
 
 
 
 
 
 
98
99
100
101
102
103
104
105
106
107
108
...
111
112
113
 
 
114
115
116
117
118
119
0
@@ -95,14 +95,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
@@ -111,8 +111,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