class Gem::AvailableSet

Constants

Tuple

Attributes

set[R]

Public Class Methods

new() click to toggle source
# File lib/rubygems/available_set.rb, line 4
def initialize
  @set = []
  @sorted = nil
end

Public Instance Methods

<<(o) click to toggle source
# File lib/rubygems/available_set.rb, line 17
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
add(spec, source) click to toggle source
# File lib/rubygems/available_set.rb, line 11
def add(spec, source)
  @set << Tuple.new(spec, source)
  @sorted = nil
  self
end
all_specs() click to toggle source
# File lib/rubygems/available_set.rb, line 43
def all_specs
  @set.map { |t| t.spec }
end
empty?() click to toggle source
# File lib/rubygems/available_set.rb, line 39
def empty?
  @set.empty?
end
inject_into_list(dep_list) click to toggle source
# File lib/rubygems/available_set.rb, line 90
def inject_into_list(dep_list)
  @set.each { |t| dep_list.add t.spec }
end
match_platform!() click to toggle source
# File lib/rubygems/available_set.rb, line 47
def match_platform!
  @set.reject! { |t| !Gem::Platform.match(t.spec.platform) }
  @sorted = nil
  self
end
pick_best!() click to toggle source
# File lib/rubygems/available_set.rb, line 69
def pick_best!
  return self if empty?

  @set = [sorted.first]
  @sorted = nil
  self
end
remove_installed!(dep) click to toggle source
# File lib/rubygems/available_set.rb, line 77
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
size() click to toggle source
# File lib/rubygems/available_set.rb, line 60
def size
  @set.size
end
sorted() click to toggle source
# File lib/rubygems/available_set.rb, line 53
def sorted
  @sorted ||= @set.sort do |a,b|
    i = b.spec <=> a.spec
    i != 0 ? i : (a.source <=> b.source)
  end
end
source_for(spec) click to toggle source
# File lib/rubygems/available_set.rb, line 64
def source_for(spec)
  f = @set.find { |t| t.spec == spec }
  f.source
end