Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix discrepancies with loading rails/init.rb from gems. [rails#324 st…
…ate:resolved]
  • Loading branch information
technoweenie committed Jun 8, 2008
1 parent 138adbf commit faad1e3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
4 changes: 4 additions & 0 deletions 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]
Expand Down
6 changes: 5 additions & 1 deletion railties/lib/rails/gem_dependency.rb
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
Expand Up @@ -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

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

Expand Down
7 changes: 4 additions & 3 deletions railties/lib/rails/plugin/locator.rb
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
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 faad1e3

Please sign in to comment.