module Pod::Downloader

Constants

Response

A response to a download request.

@attr [Pathname] location

the location where this downloaded pod is stored on disk.

@attr [Specification] spec

the specification that describes this downloaded pod.

@attr [Hash<Symbol, String>] checkout_options

the downloader parameters necessary to recreate this exact download.

Public Class Methods

download( request, target, can_cache: true, cache_path: Config.instance.cache_root + 'Pods' ) click to toggle source

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

@return [Response] The download response for this download.

@param [Request] request

the request that describes this pod download.

@param [Pathname,Nil] target

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

@param [Boolean] can_cache

whether caching is allowed.

@param [Pathname,Nil] cache_path

the path used to cache pod downloads.
# File lib/cocoapods/downloader.rb, line 29
def self.download(
  request,
  target,
  can_cache: true,
  cache_path: Config.instance.cache_root + 'Pods'
)
  can_cache &&= !Config.instance.skip_download_cache

  request = preprocess_request(request)

  if can_cache
    raise ArgumentError, 'Must provide a `cache_path` when caching.' unless cache_path
    cache = Cache.new(cache_path)
    result = cache.download_pod(request)
  else
    raise ArgumentError, 'Must provide a `target` when caching is disabled.' unless target

    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) click to toggle source

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

@return [Response, Hash<String,Specification>]

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

@param [Request] request

the request that describes this pod download.

@param [Pathname,Nil] target

the location to which this pod should be downloaded. If `nil`,
then the pod will only be cached.
# File lib/cocoapods/downloader.rb, line 73
def self.download_request(request, target)
  result = Response.new
  result.checkout_options = download_source(target, request.params)
  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

Private Class Methods

download_source(target, params) click to toggle source

Downloads a pod with the given `params` to `target`.

@param [Pathname] target

@param [Hash<Symbol,String>] params

@return [Hash] The checkout options required to re-download this exact

same source.
# File lib/cocoapods/downloader.rb, line 105
def self.download_source(target, params)
  FileUtils.rm_rf(target)
  downloader = Downloader.for_target(target, params)
  downloader.download
  target.mkpath

  if downloader.options_specific?
    params
  else
    downloader.checkout_options
  end
end
preprocess_request(request) click to toggle source

Return a new request after preprocessing by the downloader

@param [Request] request

the request that needs preprocessing

@return [Request] the preprocessed request

# File lib/cocoapods/downloader.rb, line 125
def self.preprocess_request(request)
  Request.new(
    :spec => request.spec,
    :released => request.released_pod?,
    :name => request.name,
    :params => Downloader.preprocess_options(request.params))
end