diff options
Diffstat (limited to 'lib/rubygems/source/local.rb')
-rw-r--r-- | lib/rubygems/source/local.rb | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/lib/rubygems/source/local.rb b/lib/rubygems/source/local.rb index 3227fb61b0..5ab7a467b5 100644 --- a/lib/rubygems/source/local.rb +++ b/lib/rubygems/source/local.rb @@ -9,6 +9,7 @@ class Gem::Source::Local < Gem::Source @specs = nil @api_uri = nil @uri = nil + @load_specs_names = {} end ## @@ -34,45 +35,47 @@ class Gem::Source::Local < Gem::Source end def load_specs type # :nodoc: - names = [] - - @specs = {} - - Dir["*.gem"].each do |file| - begin - pkg = Gem::Package.new(file) - rescue SystemCallError, Gem::Package::FormatError - # ignore - else - tup = pkg.spec.name_tuple - @specs[tup] = [File.expand_path(file), pkg] - - case type - when :released - unless pkg.spec.version.prerelease? - names << pkg.spec.name_tuple - end - when :prerelease - if pkg.spec.version.prerelease? - names << pkg.spec.name_tuple - end - when :latest - tup = pkg.spec.name_tuple + @load_specs_names[type] ||= begin + names = [] - cur = names.find { |x| x.name == tup.name } - if !cur - names << tup - elsif cur.version < tup.version - names.delete cur - names << tup - end + @specs = {} + + Dir["*.gem"].each do |file| + begin + pkg = Gem::Package.new(file) + rescue SystemCallError, Gem::Package::FormatError + # ignore else - names << pkg.spec.name_tuple + tup = pkg.spec.name_tuple + @specs[tup] = [File.expand_path(file), pkg] + + case type + when :released + unless pkg.spec.version.prerelease? + names << pkg.spec.name_tuple + end + when :prerelease + if pkg.spec.version.prerelease? + names << pkg.spec.name_tuple + end + when :latest + tup = pkg.spec.name_tuple + + cur = names.find { |x| x.name == tup.name } + if !cur + names << tup + elsif cur.version < tup.version + names.delete cur + names << tup + end + else + names << pkg.spec.name_tuple + end end end - end - names + names + end end def find_gem gem_name, version = Gem::Requirement.default, # :nodoc: @@ -88,7 +91,7 @@ class Gem::Source::Local < Gem::Source if version.satisfied_by?(s.version) if prerelease found << s - elsif !s.version.prerelease? + elsif !s.version.prerelease? || version.prerelease? found << s end end |