Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix discrepancies with loading rails/init.rb from gems. [#324 state:r…

…esolved]
  • Loading branch information...
commit faad1e32a8ab81890018ba89d191607778830cf0 1 parent 138adbf
@technoweenie technoweenie authored
View
4 railties/CHANGELOG
@@ -1,5 +1,9 @@
*Edge*
+* Fix discrepancies with loading rails/init.rb from gems.
+
+* Plugins check for the gem init path (rails/init.rb) before the standard plugin init path (init.rb) [Jacek Becela]
+
* Wrapped Rails.env in StringInquirer so you can do Rails.env.development? [DHH]
* Fixed that RailsInfoController wasn't considering all requests local in development mode (Edgard Castro) [#310 state:resolved]
View
6 railties/lib/rails/gem_dependency.rb
@@ -23,9 +23,13 @@ def initialize(name, options = {})
@unpack_directory = nil
end
+ def unpacked_paths
+ Dir[File.join(self.class.unpacked_path, "#{@name}-#{@version || "*"}")]
+ end
+
def add_load_paths
return if @loaded || @load_paths_added
- unpacked_paths = Dir[File.join(self.class.unpacked_path, "#{@name}-#{@version || "*"}")]
+ unpacked_paths = self.unpacked_paths
if unpacked_paths.empty?
args = [@name]
args << @requirement.to_s if @requirement
View
21 railties/lib/rails/plugin.rb
@@ -95,14 +95,14 @@ def has_init_file?
end
def evaluate_init_rb(initializer)
- if has_init_file?
- silence_warnings do
- # Allow plugins to reference the current configuration object
- config = initializer.configuration
-
- eval(IO.read(init_path), binding, init_path)
- end
- end
+ if has_init_file?
+ silence_warnings do
+ # Allow plugins to reference the current configuration object
+ config = initializer.configuration
+
+ eval(IO.read(init_path), binding, init_path)
+ end
+ end
end
end
@@ -111,8 +111,9 @@ def evaluate_init_rb(initializer)
# to Dependencies.load_paths.
class GemPlugin < Plugin
# Initialize this plugin from a Gem::Specification.
- def initialize(spec)
- super(File.join(spec.full_gem_path))
+ def initialize(spec, gem)
+ directory = (gem.frozen? && gem.unpacked_paths.first) || File.join(spec.full_gem_path)
+ super(directory)
@name = spec.name
end
View
7 railties/lib/rails/plugin/locator.rb
@@ -78,8 +78,9 @@ def locate_plugins_under(base_path)
# a <tt>rails/init.rb</tt> file.
class GemLocator < Locator
def plugins
- specs = initializer.configuration.gems.map(&:specification)
- specs += Gem.loaded_specs.values.select do |spec|
+ gem_index = initializer.configuration.gems.inject({}) { |memo, gem| memo.update gem.specification => gem }
+ specs = gem_index.keys
+ specs += Gem.loaded_specs.values.select do |spec|
spec.loaded_from && # prune stubs
File.exist?(File.join(spec.full_gem_path, "rails", "init.rb"))
end
@@ -91,7 +92,7 @@ def plugins
deps.add(*specs) unless specs.empty?
deps.dependency_order.collect do |spec|
- Rails::GemPlugin.new(spec)
+ Rails::GemPlugin.new(spec, gem_index[spec])
end
end
end
View
2  railties/test/plugin_loader_test.rb
@@ -94,7 +94,7 @@ def test_should_accept_plugin_names_given_as_strings
def test_should_add_plugin_load_paths_to_global_LOAD_PATH_array
only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
- stubbed_application_lib_index_in_LOAD_PATHS = 5
+ stubbed_application_lib_index_in_LOAD_PATHS = 4
@loader.stubs(:application_lib_index).returns(stubbed_application_lib_index_in_LOAD_PATHS)
@loader.add_plugin_load_paths
Please sign in to comment.
Something went wrong with that request. Please try again.