class Gem::Resolver::APISet

全局 rubygems 池,可通过 rubygems.org API 获取。返回 APISpecification 的实例。

属性

source[R]

从中获取 gem 的 Gem::Source

uri[R]

获取 gem 的相应位置。

公共类方法

new(dep_uri = "https://index.rubygems.org/info/") 点击以切换源代码

创建一个新的 APISet,它将使用 RubyGems API URL dep_uriuri 中检索 gem,该 API URL 在 guides.rubygems.org/rubygems-org-api 中描述

调用超类方法
# File rubygems/resolver/api_set.rb, line 30
def initialize(dep_uri = "https://index.rubygems.org/info/")
  super()

  dep_uri = Gem::URI dep_uri unless Gem::URI === dep_uri

  @dep_uri = dep_uri
  @uri     = dep_uri + ".."

  @data   = Hash.new {|h,k| h[k] = [] }
  @source = Gem::Source.new @uri

  @to_fetch = []
end

公共实例方法

find_all(req) 点击以切换源代码

返回一个与 DependencyRequest req 匹配的 APISpecification 对象数组。

# File rubygems/resolver/api_set.rb, line 48
def find_all(req)
  res = []

  return res unless @remote

  if @to_fetch.include?(req.name)
    prefetch_now
  end

  versions(req.name).each do |ver|
    if req.dependency.match? req.name, ver[:number], @prerelease
      res << Gem::Resolver::APISpecification.new(self, ver)
    end
  end

  res
end
prefetch(reqs) 点击以切换源代码

解析器运行的提示,允许 Set 为 DependencyRequests reqs 获取数据。

# File rubygems/resolver/api_set.rb, line 70
def prefetch(reqs)
  return unless @remote
  names = reqs.map {|r| r.dependency.name }
  needed = names - @data.keys - @to_fetch

  @to_fetch += needed
end

私有实例方法

lines(str) 点击以切换源代码
# File rubygems/resolver/api_set.rb, line 129
def lines(str)
  lines = str.split("\n")
  header = lines.index("---")
  header ? lines[header + 1..-1] : lines
end
parse_gem(string) 点击以切换源代码
# File rubygems/resolver/api_set.rb, line 135
def parse_gem(string)
  @gem_parser ||= GemParser.new
  @gem_parser.parse(string)
end