diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/index.rb | 23 | ||||
-rw-r--r-- | lib/bundler/source.rb | 33 |
2 files changed, 35 insertions, 21 deletions
diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb index f6b45d06dc..1ca9af19a0 100644 --- a/lib/bundler/index.rb +++ b/lib/bundler/index.rb @@ -8,6 +8,9 @@ module Bundler i end + attr_reader :specs + protected :specs + def initialize @cache = {} @specs = Hash.new { |h,k| h[k] = [] } @@ -17,7 +20,10 @@ module Bundler super @cache = {} @specs = Hash.new { |h,k| h[k] = [] } - merge!(o) + + o.specs.each do |name, array| + @specs[name] = array.dup + end end def empty? @@ -59,7 +65,7 @@ module Bundler arr = @specs[spec.name] arr.delete_if do |s| - s.version == spec.version && s.platform == spec.platform + same_version?(s.version, spec.version) && s.platform == spec.platform end arr << spec @@ -91,10 +97,21 @@ module Bundler def search_by_spec(spec) @specs[spec.name].select do |s| - s.version == spec.version && Gem::Platform.new(s.platform) == Gem::Platform.new(spec.platform) + same_version?(s.version, spec.version) && Gem::Platform.new(s.platform) == Gem::Platform.new(spec.platform) end end + def same_version?(a, b) + regex = /^(.*?)(?:\.0)*$/ + + ret = a.to_s[regex, 1] == b.to_s[regex, 1] + end + + def spec_satisfies_dependency?(spec, dep) + return false unless dep.name === spec.name + dep.requirement.satisfied_by?(spec.version) + end + def search_by_dependency(dependency) @cache[dependency.hash] ||= begin specs = @specs[dependency.name] diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index e5eb86f881..685ea47561 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -158,7 +158,7 @@ module Bundler @installed_specs ||= begin idx = Index.new have_bundler = false - Gem::SourceIndex.from_installed_gems.to_a.reverse.each do |dont_use_this_var, spec| + Gem.source_index.to_a.reverse.each do |dont_use_this_var, spec| next if spec.name == 'bundler' && spec.version.to_s != VERSION have_bundler = true if spec.name == 'bundler' spec.source = self @@ -185,27 +185,24 @@ module Bundler def cached_specs @cached_specs ||= begin - idx = Index.new - @caches.each do |path| - Dir["#{path}/*.gem"].each do |gemfile| - next if gemfile =~ /bundler\-[\d\.]+?\.gem/ - - # Try to skip decompressing the gem to get at the gemspec if possible - cached_gemspec = gemfile.gsub(%r{cache/(.*?)\.gem}, 'specifications/\1.gemspec') - s = Gem::Specification.load(cached_gemspec) if File.exist?(cached_gemspec) - - begin - s ||= Gem::Format.from_file_by_path(gemfile).spec - rescue Gem::Package::FormatError - raise GemspecError, "Could not read gem at #{gemfile}. It may be corrupted." - end + idx = installed_specs.dup + + path = Bundler.app_cache + Dir["#{path}/*.gem"].each do |gemfile| + next if gemfile =~ /bundler\-[\d\.]+?\.gem/ - s.source = self - idx << s + begin + s ||= Gem::Format.from_file_by_path(gemfile).spec + rescue Gem::Package::FormatError + raise GemspecError, "Could not read gem at #{gemfile}. It may be corrupted." end + + s.source = self + idx << s end - idx end + + idx end def remote_specs |