class Bundler::CompactIndexClient::Parser

公共类方法

new(compact_index) 点击切换源码

‘compact_index` - 一个响应namesversionsinfo(name, checksum)的对象,

returning the file contents as a string
# File bundler/compact_index_client/parser.rb, line 8
def initialize(compact_index)
  @compact_index = compact_index
  @info_checksums = nil
  @versions_by_name = nil
  @available = nil
  @gem_parser = nil
end

公共实例方法

available?() 点击切换源码
# File bundler/compact_index_client/parser.rb, line 46
def available?
  return @available unless @available.nil?
  @available = !info_checksums.empty?
end
info(name) 点击切换源码
# File bundler/compact_index_client/parser.rb, line 41
def info(name)
  data = @compact_index.info(name, info_checksums[name])
  lines(data).map {|line| gem_parser.parse(line).unshift(name) }
end
names() 点击切换源码
# File bundler/compact_index_client/parser.rb, line 16
def names
  lines(@compact_index.names)
end
versions() 点击切换源码
# File bundler/compact_index_client/parser.rb, line 20
def versions
  @versions_by_name ||= Hash.new {|hash, key| hash[key] = [] }
  @info_checksums = {}

  lines(@compact_index.versions).each do |line|
    name, versions_string, checksum = line.split(" ", 3)
    @info_checksums[name] = checksum || ""
    versions_string.split(",") do |version|
      delete = version.delete_prefix!("-")
      version = version.split("-", 2).unshift(name)
      if delete
        @versions_by_name[name].delete(version)
      else
        @versions_by_name[name] << version
      end
    end
  end

  @versions_by_name
end

私有实例方法

gem_parser() 点击切换源码
# File bundler/compact_index_client/parser.rb, line 66
def gem_parser
  @gem_parser ||= GemParser.new
end
info_checksums() 点击切换源码
# File bundler/compact_index_client/parser.rb, line 53
def info_checksums
  @info_checksums ||= lines(@compact_index.versions).each_with_object({}) do |line, checksums|
    parse_version_checksum(line, checksums)
  end
end
lines(data) 点击切换源码
# File bundler/compact_index_client/parser.rb, line 59
def lines(data)
  return [] if data.nil? || data.empty?
  lines = data.split("\n")
  header = lines.index("---")
  header ? lines[header + 1..-1] : lines
end
parse_version_checksum(line, checksums) 点击切换源码

这与 `split(“ ”, 3)` 大致相同,但它避免了分配额外的对象。 当解析版本时,每个 gem 至少会调用此方法一次。

# File bundler/compact_index_client/parser.rb, line 72
def parse_version_checksum(line, checksums)
  return unless (name_end = line.index(" ")) # Artifactory bug causes blank lines in artifactor index files
  return unless (checksum_start = line.index(" ", name_end + 1) + 1)
  checksum_end = line.size - checksum_start

  line.freeze # allows slicing into the string to not allocate a copy of the line
  name = line[0, name_end]
  checksum = line[checksum_start, checksum_end]
  checksums[name.freeze] = checksum # freeze name since it is used as a hash key
end