Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make refresh_specs more resilient. Always add vendor/gems to gem sear…

…ch path. Use Gem.clear_paths to ensure we get a current searcher.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
commit 01433af6a5dd5bcd71a70574e7d0b356ba7b0246 1 parent 62ffc6e
@al2o3cr al2o3cr authored NZKoz committed
View
1  railties/lib/initializer.rb
@@ -267,6 +267,7 @@ def add_plugin_load_paths
end
def add_gem_load_paths
+ Rails::GemDependency.add_frozen_gem_path
unless @configuration.gems.empty?
require "rubygems"
@configuration.gems.each { |gem| gem.add_load_paths }
View
37 railties/lib/rails/gem_dependency.rb
@@ -18,11 +18,14 @@ def self.unpacked_path
def self.add_frozen_gem_path
@@paths_loaded ||= begin
- Gem.source_index = Rails::VendorGemSourceIndex.new(Gem.source_index)
+ source_index = Rails::VendorGemSourceIndex.new(Gem.source_index)
+ Gem.clear_paths
+ Gem.source_index = source_index
# loaded before us - we can't change them, so mark them
Gem.loaded_specs.each do |name, spec|
@@framework_gems[name] = spec
end
+ true
end
end
@@ -170,19 +173,27 @@ def refresh_spec(directory)
exact_dep = Gem::Dependency.new(name, "= #{specification.version}")
matches = real_gems.search(exact_dep)
installed_spec = matches.first
- if installed_spec
- # we have a real copy
- # get a fresh spec - matches should only have one element
- # note that there is no reliable method to check that the loaded
- # spec is the same as the copy from real_gems - Gem.activate changes
- # some of the fields
- real_spec = Gem::Specification.load(matches.first.loaded_from)
- write_spec(directory, real_spec)
- puts "Reloaded specification for #{name} from installed gems."
+ if File.exist?(File.dirname(spec_filename(directory)))
+ if installed_spec
+ # we have a real copy
+ # get a fresh spec - matches should only have one element
+ # note that there is no reliable method to check that the loaded
+ # spec is the same as the copy from real_gems - Gem.activate changes
+ # some of the fields
+ real_spec = Gem::Specification.load(matches.first.loaded_from)
+ write_spec(directory, real_spec)
+ puts "Reloaded specification for #{name} from installed gems."
+ else
+ # the gem isn't installed locally - write out our current specs
+ write_spec(directory, specification)
+ puts "Gem #{name} not loaded locally - writing out current spec."
+ end
else
- # the gem isn't installed locally - write out our current specs
- write_spec(directory, specification)
- puts "Gem #{name} not loaded locally - writing out current spec."
+ if framework_gem?
+ puts "Gem directory for #{name} not found - check if it's loading before rails."
+ else
+ puts "Something bad is going on - gem directory not found for #{name}."
+ end
end
end
View
3  railties/lib/tasks/gems.rake
@@ -6,10 +6,11 @@ task :gems => 'gems:base' do
puts
puts "I = Installed"
puts "F = Frozen"
+ puts "R = Framework (loaded before rails starts)"
end
def print_gem_status(gem, indent=1)
- code = gem.loaded? ? (gem.frozen? ? "F" : "I") : " "
+ code = gem.loaded? ? (gem.frozen? ? (gem.framework_gem? ? "R" : "F") : "I") : " "
puts " "*(indent-1)+" - [#{code}] #{gem.name} #{gem.requirement.to_s}"
gem.dependencies.each { |g| print_gem_status(g, indent+1)} if gem.loaded?
end
Please sign in to comment.
Something went wrong with that request. Please try again.