Permalink
Browse files

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

…esolved]
  • Loading branch information...
1 parent 924244b commit e1bd75a92285c29269270e708e49d7cd5fabac36 @technoweenie technoweenie committed Jun 8, 2008
View
@@ -1,6 +1,5 @@
*Edge*
-
* Wrapped Rails.env in StringQuestioneer so you can do Rails.env.development? [DHH]
* Add the gem load paths before the framework is loaded, so certain gems like RedCloth and BlueCloth can be frozen.
@@ -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
@@ -87,14 +87,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
@@ -103,8 +103,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
@@ -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
@@ -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

0 comments on commit e1bd75a

Please sign in to comment.