Class: Bundler::CompactIndexClient::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/compact_index_client/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(compact_index) ⇒ Parser

‘compact_index` - an object responding to #names, #versions, #info(name, checksum),

returning the file contents as a string


8
9
10
11
12
13
14
# File 'lib/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

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/bundler/compact_index_client/parser.rb', line 46

def available?
  return @available unless @available.nil?
  @available = !info_checksums.empty?
end

#info(name) ⇒ Object



41
42
43
44
# File 'lib/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

#namesObject



16
17
18
# File 'lib/bundler/compact_index_client/parser.rb', line 16

def names
  lines(@compact_index.names)
end

#versionsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/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