Class: Pod::Downloader::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/downloader/cache.rb

Overview

The class responsible for managing Pod downloads, transparently caching them in a cache directory.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Cache

Initialize a new instance

Parameters:

  • root (Pathname, String)

    see #root



20
21
22
23
# File 'lib/cocoapods/downloader/cache.rb', line 20

def initialize(root)
  @root = Pathname(root)
  ensure_matching_version
end

Instance Attribute Details

#rootPathname (readonly)

Returns The root directory where this cache store its downloads.

Returns:

  • (Pathname)

    The root directory where this cache store its downloads.



13
14
15
# File 'lib/cocoapods/downloader/cache.rb', line 13

def root
  @root
end

Instance Method Details

#cache_descriptors_per_podHash<String, Hash<Symbol, String>>

Returns A hash whose keys are the pod name And values are a hash with the following keys: :spec_file : path to the spec file :name : name of the pod :version : pod version :release : boolean to tell if that’s a release pod :slug : the slug path where the pod cache is located.

Returns:

  • (Hash<String, Hash<Symbol, String>>)

    A hash whose keys are the pod name And values are a hash with the following keys: :spec_file : path to the spec file :name : name of the pod :version : pod version :release : boolean to tell if that’s a release pod :slug : the slug path where the pod cache is located



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cocoapods/downloader/cache.rb', line 50

def cache_descriptors_per_pod
  specs_dir = root + 'Specs'
  release_specs_dir = specs_dir + 'Release'
  return {} unless specs_dir.exist?

  spec_paths = specs_dir.find.select { |f| f.fnmatch('*.podspec.json') }
  spec_paths.reduce({}) do |hash, spec_path|
    spec = Specification.from_file(spec_path)
    hash[spec.name] ||= []
    is_release = spec_path.to_s.start_with?(release_specs_dir.to_s)
    request = Downloader::Request.new(:spec => spec, :released => is_release)
    hash[spec.name] << {
      :spec_file => spec_path,
      :name => spec.name,
      :version => spec.version,
      :release => is_release,
      :slug => root + request.slug,
    }
    hash
  end
end

#download_pod(request) ⇒ Response

Downloads the Pod from the given ‘request`

Parameters:

  • request (Request)

    the request to be downloaded.

Returns:

  • (Response)

    the response from downloading ‘request`



32
33
34
35
36
37
38
39
# File 'lib/cocoapods/downloader/cache.rb', line 32

def download_pod(request)
  cached_pod(request) || uncached_pod(request)
rescue Informative
  raise
rescue
  UI.puts("\n[!] Error installing #{request.name}".red)
  raise
end