Class: Bundler::Fetcher::CompactIndex

Inherits:
Base
  • Object
show all
Defined in:
lib/bundler/fetcher/compact_index.rb

Instance Attribute Summary

Attributes inherited from Base

#display_uri, #downloader, #remote

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#fetch_uri, #initialize, #remote_uri

Constructor Details

This class inherits a constructor from Bundler::Fetcher::Base

Class Method Details

.compact_index_request(method_name) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bundler/fetcher/compact_index.rb', line 10

def self.compact_index_request(method_name)
  method = instance_method(method_name)
  undef_method(method_name)
  define_method(method_name) do |*args, &blk|
    begin
      method.bind(self).call(*args, &blk)
    rescue NetworkDownError, CompactIndexClient::Updater::MisMatchedChecksumError => e
      raise HTTPError, e.message
    rescue AuthenticationRequiredError
      # We got a 401 from the server. Just fail.
      raise
    rescue HTTPError => e
      Bundler.ui.trace(e)
      nil
    end
  end
end

Instance Method Details

#api_fetcher?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/bundler/fetcher/compact_index.rb', line 72

def api_fetcher?
  true
end

#available?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
68
69
# File 'lib/bundler/fetcher/compact_index.rb', line 61

def available?
  user_home = Pathname.new(Bundler.rubygems.user_home)
  return nil unless user_home.directory? && user_home.writable?
  # Read info file checksums out of /versions, so we can know if gems are up to date
  fetch_uri.scheme != "file" && compact_index_client.update_and_parse_checksums!
rescue CompactIndexClient::Updater::MisMatchedChecksumError => e
  Bundler.ui.warn(e.message)
  nil
end

#fetch_spec(spec) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/bundler/fetcher/compact_index.rb', line 51

def fetch_spec(spec)
  spec -= [nil, "ruby", ""]
  contents = compact_index_client.spec(*spec)
  return nil if contents.nil?
  contents.unshift(spec.first)
  contents[3].map! {|d| Gem::Dependency.new(*d) }
  EndpointSpecification.new(*contents)
end

#specs(gem_names) ⇒ Object



28
29
30
# File 'lib/bundler/fetcher/compact_index.rb', line 28

def specs(gem_names)
  specs_for_names(gem_names)
end

#specs_for_names(gem_names) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bundler/fetcher/compact_index.rb', line 33

def specs_for_names(gem_names)
  gem_info = []
  complete_gems = []
  remaining_gems = gem_names.dup

  until remaining_gems.empty?
    Bundler.ui.debug "Looking up gems #{remaining_gems.inspect}"

    deps = compact_index_client.dependencies(remaining_gems)
    next_gems = deps.map {|d| d[3].map(&:first).flatten(1) }.flatten(1).uniq
    deps.each {|dep| gem_info << dep }
    complete_gems.push(*deps.map(&:first)).uniq!
    remaining_gems = next_gems - complete_gems
  end

  gem_info
end