Skip to content

Commit

Permalink
Fix discrepancies with loading rails/init.rb from gems. [#324 state:r…
Browse files Browse the repository at this point in the history
…esolved]
  • Loading branch information
technoweenie committed Jun 19, 2008
1 parent 924244b commit e1bd75a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
1 change: 0 additions & 1 deletion railties/CHANGELOG
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 5 additions & 1 deletion railties/lib/rails/gem_dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions railties/lib/rails/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
7 changes: 4 additions & 3 deletions railties/lib/rails/plugin/locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion railties/test/plugin_loader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e1bd75a

Please sign in to comment.