Module: Pod::Downloader

Defined in:
lib/cocoapods/downloader.rb,
lib/cocoapods/downloader/cache.rb,
lib/cocoapods/downloader/request.rb,
lib/cocoapods/downloader/response.rb

Defined Under Namespace

Classes: Base, Cache, DownloaderError, Request, Response

Class Method Summary collapse

Class Method Details

.download(request, target, cache_path: !Config.instance.skip_download_cache && Config.instance.clean? && Config.instance.cache_root + 'Pods') ⇒ Response

Downloads a pod from the given ‘request` to the given `target` location.

Parameters:

  • request (Request)

    the request that describes this pod download.

  • target (Pathname, Nil)

    the location to which this pod should be downloaded. If ‘nil`, then the pod will only be cached.

  • cache_path (Pathname, Nil) (defaults to: !Config.instance.skip_download_cache && Config.instance.clean? && Config.instance.cache_root + 'Pods')

    the path used to cache pod downloads. If ‘nil`, then no caching will be done.

Returns:

  • (Response)

    The download response for this download.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cocoapods/downloader.rb', line 27

def self.download(
  request,
  target,
  cache_path: !Config.instance.skip_download_cache && Config.instance.clean? && Config.instance.cache_root + 'Pods'
)
  if cache_path
    cache = Cache.new(cache_path)
    result = cache.download_pod(request)
  else
    require 'cocoapods/installer/pod_source_preparer'
    result, _ = download_request(request, target)
    Installer::PodSourcePreparer.new(result.spec, result.location).prepare!
  end

  if target && result.location && target != result.location
    UI.message "Copying #{request.name} from `#{result.location}` to #{UI.path target}", '> ' do
      FileUtils.rm_rf target
      FileUtils.cp_r(result.location, target)
    end
  end
  result
end

.download_request(request, target) ⇒ Response, Hash<String,Specification>

Performs the download from the given ‘request` to the given `target` location.

Parameters:

  • request (Request)

    the request that describes this pod download.

  • target (Pathname, Nil)

    the location to which this pod should be downloaded. If ‘nil`, then the pod will only be cached.

Returns:

  • (Response, Hash<String,Specification>)

    The download response for this download, and the specifications for this download grouped by name.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cocoapods/downloader.rb', line 63

def self.download_request(request, target)
  result = Response.new
  result.checkout_options = download_source(request.name, target, request.params, request.head?)
  result.location = target

  if request.released_pod?
    result.spec = request.spec
    podspecs = { request.name => request.spec }
  else
    podspecs = Sandbox::PodspecFinder.new(target).podspecs
    podspecs[request.name] = request.spec if request.spec
    podspecs.each do |name, spec|
      if request.name == name
        result.spec = spec
      end
    end
  end

  [result, podspecs]
end