Permalink
Browse files

Finish stage 1 of SpecFetcher refactoring

  • Loading branch information...
evanphx committed Feb 28, 2012
1 parent e5769be commit eb1bc0ffdb190426f36f28c69cd0a91e3d9f478c
@@ -195,8 +195,7 @@ def which_to_update highest_installed_gems, gem_names, system = false
fetcher = Gem::SpecFetcher.fetcher
- spec_tuples = fetcher.find_matching dependency, false, true,
- options[:prerelease]
+ spec_tuples, errs = fetcher.search_for_dependency dependency
matching_gems = spec_tuples.select do |(name, _, platform),|
name == l_name and Gem::Platform.match platform
@@ -183,7 +183,7 @@ def initialize
@all = Hash.new { |h,k| h[k] = [] }
- @f.list(true, true).each do |uri, specs|
+ @f.available_specs(:released).each do |uri, specs|
specs.each do |name, ver, plat|
@all[name] << [uri, ver, plat]
end
@@ -198,10 +198,6 @@ def spec_for_dependency(dependency, matching_platform=true)
return [specs, errors]
end
- def find_matching(dep, *args)
- search_for_dependency(dep).first
- end
-
##
# Suggests a gem based on the supplied +gem_name+. Returns a string
# of the gem name if an approximate match can be found or nil
@@ -211,7 +207,7 @@ def find_matching(dep, *args)
def suggest_gems_from_name gem_name
gem_name = gem_name.downcase
max = gem_name.size / 2
- specs = list.values.flatten 1
+ specs = available_specs(:complete).values.flatten 1
matches = specs.map { |name, version, platform|
next unless Gem::Platform.match platform
@@ -230,44 +226,6 @@ def suggest_gems_from_name gem_name
matches.first(5).map { |name, dist| name }
end
- ##
- # Returns a list of gems available for each source in Gem::sources. If
- # +all+ is true, all released versions are returned instead of only latest
- # versions. If +prerelease+ is true, include prerelease versions.
-
- def list(all = false, prerelease = false)
- # TODO: make type the only argument
- type = if all
- :all
- elsif prerelease
- :prerelease
- else
- :latest
- end
-
- list = {}
- file = FILES[type]
- cache = @caches[type]
-
- Gem.sources.each do |source_uri|
- source_uri = URI.parse source_uri
-
- unless cache.include? source_uri
- cache[source_uri] = load_specs source_uri, file
- end
-
- list[source_uri] = cache[source_uri]
- end
-
- if type == :all
- list.values.map do |gems|
- gems.reject! { |g| !g[1] || g[1].prerelease? }
- end
- end
-
- list
- end
-
##
# Returns a list of gems available for each source in Gem::sources.
#
@@ -957,9 +957,9 @@ def self.outdated
latest_specs.each do |local|
dependency = Gem::Dependency.new local.name, ">= #{local.version}"
- remotes = fetcher.find_matching dependency
- remotes = remotes.map { |(_, version, _), _| version }
- latest = remotes.sort.last
+ remotes, err = fetcher.search_for_dependency dependency
+ remotes = remotes.map { |(_, version, _), _| version }
+ latest = remotes.sort.last
outdateds << local.name if latest and local.version < latest
end
@@ -36,6 +36,14 @@ def setup
@fetcher.data["#{@gem_repo}prerelease_specs.#{v}.gz"] = p_zip
@sf = Gem::SpecFetcher.new
+
+ @released = [["a", Gem::Version.new("1"), "ruby"],
+ ["a", Gem::Version.new("2"), "ruby"],
+ ["a_evil", Gem::Version.new("9"), "ruby"],
+ ["c", Gem::Version.new("1.2"), "ruby"],
+ ['dep_x', Gem::Version.new(1), 'ruby'],
+ ["pl", Gem::Version.new("1"), "i386-linux"],
+ ['x', Gem::Version.new(1), 'ruby']]
end
def test_spec_for_dependency_all
@@ -173,71 +181,57 @@ def test_fetch_spec_platform_ruby
assert_equal @a1.full_name, spec.full_name
end
- def test_list
- specs = @sf.list
+ def test_available_specs_latest
+ specs = @sf.available_specs(:latest)
assert_equal [@uri], specs.keys
assert_equal @latest_specs, specs[@uri].sort
end
- def test_list_all
- specs = @sf.list true
+ def test_available_specs_released
+ specs = @sf.available_specs(:released)
assert_equal [@uri], specs.keys
- assert_equal([["a", Gem::Version.new("1"), "ruby"],
- ["a", Gem::Version.new("2"), "ruby"],
- ["a_evil", Gem::Version.new("9"), "ruby"],
- ["c", Gem::Version.new("1.2"), "ruby"],
- ['dep_x', Gem::Version.new(1), 'ruby'],
- ["pl", Gem::Version.new("1"), "i386-linux"],
- ['x', Gem::Version.new(1), 'ruby']],
- specs[@uri].sort)
+ assert_equal @released, specs[@uri].sort
end
- def test_list_cache
- specs = @sf.list
+ def test_available_specs_complete
+ specs = @sf.available_specs(:complete)
- refute specs[@uri].empty?
-
- @fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = nil
+ assert_equal [@uri], specs.keys
- cached_specs = @sf.list
+ comp = @prerelease_specs + @released
- assert_equal specs, cached_specs
+ assert_equal comp.sort, specs[@uri].sort
end
- def test_list_cache_all
- specs = @sf.list true
+ def test_available_specs_cache
+ specs = @sf.available_specs(:latest)
refute specs[@uri].empty?
- @fetcher.data["#{@gem_repo}/specs.#{Gem.marshal_version}.gz"] = nil
+ @fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = nil
- cached_specs = @sf.list true
+ cached_specs = @sf.available_specs(:latest)
assert_equal specs, cached_specs
end
- def test_list_latest_all
- specs = @sf.list false
+ def test_available_specs_cache_released
+ specs = @sf.available_specs(:released)
- assert_equal [@latest_specs], specs.values
+ refute specs[@uri].empty?
- specs = @sf.list true
+ @fetcher.data["#{@gem_repo}/specs.#{Gem.marshal_version}.gz"] = nil
- assert_equal([[["a", Gem::Version.new("1"), "ruby"],
- ["a", Gem::Version.new("2"), "ruby"],
- ["a_evil", Gem::Version.new("9"), "ruby"],
- ["c", Gem::Version.new("1.2"), "ruby"],
- ["dep_x", Gem::Version.new("1"), "ruby"],
- ["pl", Gem::Version.new("1"), "i386-linux"],
- ["x", Gem::Version.new("1"), "ruby"]]],
- specs.values, 'specs file not loaded')
+ cached_specs = @sf.available_specs(:released)
+
+ assert_equal specs, cached_specs
end
- def test_list_prerelease
- specs = @sf.list false, true
+ def test_available_specs_prerelease
+ specs = @sf.available_specs(:prerelease)
assert_equal @prerelease_specs, specs[@uri].sort
end

0 comments on commit eb1bc0f

Please sign in to comment.