1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/rubygems/available_set.rb
drbrain a6c92a85e4 * lib/rubygems/available_set.rb: Undent for style
* lib/rubygems/dependency_installer.rb:  Pick latest prerelease gem to
  install.  Fixes RubyGems bug #468.
* test/rubygems/test_gem_dependency_installer.rb:  Test for the above.

* lib/rubygems/dependency_installer.rb:  Don't display "Done installing
  documentation" if documentation will not be installed.
* lib/rubygems/rdoc.rb:  ditto

* lib/rubygems/dependency_list.rb:  Use Array#concat for Ruby 1.x
  performance.

* lib/rubygems/installer.rb:  Use formatted program name when comparing
  executables.  RubyGems pull request #471
* test/rubygems/test_gem_installer.rb:  Test for the above.

* lib/rubygems/package.rb:  Use more explicit feature check to work
  around JRuby bug #552

* lib/rubygems/ssl_certs/GeoTrust_Global_CA.pem:  Added GeoTrust root
  certificate.

* test/rubygems/test_gem_source_list.rb:  Use "example" instead of real
  hostname


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-27 23:20:57 +00:00

93 lines
1.6 KiB
Ruby

class Gem::AvailableSet
Tuple = Struct.new(:spec, :source)
def initialize
@set = []
@sorted = nil
end
attr_reader :set
def add(spec, source)
@set << Tuple.new(spec, source)
@sorted = nil
self
end
def <<(o)
case o
when Gem::AvailableSet
s = o.set
when Array
s = o.map do |sp,so|
if !sp.kind_of?(Gem::Specification) or !so.kind_of?(Gem::Source)
raise TypeError, "Array must be in [[spec, source], ...] form"
end
Tuple.new(sp,so)
end
else
raise TypeError, "must be a Gem::AvailableSet"
end
@set += s
@sorted = nil
self
end
def empty?
@set.empty?
end
def all_specs
@set.map { |t| t.spec }
end
def match_platform!
@set.reject! { |t| !Gem::Platform.match(t.spec.platform) }
@sorted = nil
self
end
def sorted
@sorted ||= @set.sort do |a,b|
i = b.spec <=> a.spec
i != 0 ? i : (a.source <=> b.source)
end
end
def size
@set.size
end
def source_for(spec)
f = @set.find { |t| t.spec == spec }
f.source
end
def pick_best!
return self if empty?
@set = [sorted.first]
@sorted = nil
self
end
def remove_installed!(dep)
@set.reject! do |t|
# already locally installed
Gem::Specification.any? do |installed_spec|
dep.name == installed_spec.name and
dep.requirement.satisfied_by? installed_spec.version
end
end
@sorted = nil
self
end
def inject_into_list(dep_list)
@set.each { |t| dep_list.add t.spec }
end
end