class Gem::AvailableSet

常量

Tuple

属性

set[R]

公共类方法

new() 点击切换源代码
# File rubygems/available_set.rb, line 10
def initialize
  @set = []
  @sorted = nil
  @remote = true
end

公共实例方法

<<(o) 点击切换源代码
# File rubygems/available_set.rb, line 24
def <<(o)
  case o
  when Gem::AvailableSet
    s = o.set
  when Array
    s = o.map do |sp,so|
      if !sp.is_a?(Gem::Specification) || !so.is_a?(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) 点击切换源代码
# File rubygems/available_set.rb, line 18
def add(spec, source)
  @set << Tuple.new(spec, source)
  @sorted = nil
  self
end
all_specs() 点击切换源代码
# File rubygems/available_set.rb, line 72
def all_specs
  @set.map(&:spec)
end
each() { |tuple| ... } 点击切换源代码

遍历此 AvailableSet 中的每个 Tuple

# File rubygems/available_set.rb, line 49
def each
  return enum_for __method__ unless block_given?

  @set.each do |tuple|
    yield tuple
  end
end
each_spec() { |spec| ... } 点击切换源代码

遍历此 AvailableSet 中每个 TupleGem::Specification

# File rubygems/available_set.rb, line 60
def each_spec
  return enum_for __method__ unless block_given?

  each do |tuple|
    yield tuple.spec
  end
end
empty?() 点击切换源代码
# File rubygems/available_set.rb, line 68
def empty?
  @set.empty?
end
find_all(req) 点击切换源代码

供 Resolver 使用,将 AvailableSet 用作搜索 Set 的协议。

# File rubygems/available_set.rb, line 126
def find_all(req)
  dep = req.dependency

  match = @set.find_all do |t|
    dep.match? t.spec
  end

  match.map do |t|
    Gem::Resolver::LocalSpecification.new(self, t.spec, t.source)
  end
end
inject_into_list(dep_list) 点击切换源代码
# File rubygems/available_set.rb, line 162
def inject_into_list(dep_list)
  @set.each {|t| dep_list.add t.spec }
end
match_platform!() 点击切换源代码
# File rubygems/available_set.rb, line 76
def match_platform!
  @set.reject! {|t| !Gem::Platform.match_spec?(t.spec) }
  @sorted = nil
  self
end
pick_best!() 点击切换源代码
# File rubygems/available_set.rb, line 141
def pick_best!
  return self if empty?

  @set = [sorted.first]
  @sorted = nil
  self
end
prefetch(reqs) 点击切换源代码
# File rubygems/available_set.rb, line 138
def prefetch(reqs)
end
remove_installed!(dep) 点击切换源代码
# File rubygems/available_set.rb, line 149
def remove_installed!(dep)
  @set.reject! do |_t|
    # already locally installed
    Gem::Specification.any? do |installed_spec|
      dep.name == installed_spec.name &&
        dep.requirement.satisfied_by?(installed_spec.version)
    end
  end

  @sorted = nil
  self
end
size() 点击切换源代码
# File rubygems/available_set.rb, line 89
def size
  @set.size
end
sorted() 点击切换源代码
# File rubygems/available_set.rb, line 82
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) 点击切换源代码
# File rubygems/available_set.rb, line 93
def source_for(spec)
  f = @set.find {|t| t.spec == spec }
  f.source
end
to_request_set(development = :none) 点击切换源代码

将此 AvailableSet 转换为可用于安装 gem 的 RequestSet。

如果 development 为 :none,则不安装开发依赖项。其他选项为 :shallow(仅用于此集合中 gem 的直接开发依赖项)或 :all(用于所有开发依赖项)。

# File rubygems/available_set.rb, line 106
def to_request_set(development = :none)
  request_set = Gem::RequestSet.new
  request_set.development = development == :all

  each_spec do |spec|
    request_set.always_install << spec

    request_set.gem spec.name, spec.version
    request_set.import spec.development_dependencies if
      development == :shallow
  end

  request_set
end