class Pod::Downloader::Base

The base class defines the common behaviour of the downloaders.

@abstract Subclass and implement {#download}.

@private

Attributes

options[R]

@return [Hash={Symbol=>String}] options specific to each concrete

downloader.
target_path[R]

@return [Pathname] the destination folder for the download.

url[R]

@return [String] the url of the remote source.

Public Class Methods

executable(name) click to toggle source

Defines two methods for an executable, based on its name. The bang version raises if the executable terminates with a non-zero exit code.

For example

executable :git

generates

def git(command)
  Hooks.execute_with_check("git", command, false)
end

def git!(command)
  Hooks.execute_with_check("git", command, true)
end

@param [Symbol] name

the name of the executable.

@return [void]

# File lib/cocoapods-downloader/base.rb, line 169
def self.executable(name)
  define_method(name) do |*command|
    execute_command(name.to_s, command.flatten, false)
  end

  define_method(name.to_s + '!') do |*command|
    execute_command(name.to_s, command.flatten, true)
  end
end
new(target_path, url, options) click to toggle source

@param [String, Pathname] target_path @see target_path @param [String] url @see url @param [Hash={Symbol=>String}] options @see options

# File lib/cocoapods-downloader/base.rb, line 48
def initialize(target_path, url, options)
  require 'pathname'
  @target_path = Pathname.new(target_path)
  @url = url
  @options = options

  unrecognized_options = options.keys - self.class.options
  unless unrecognized_options.empty?
    raise DownloaderError, "Unrecognized options `#{unrecognized_options}`"
  end
end
options() click to toggle source

@abstract Override in subclasses.

@return [Array<Symbol>] the options accepted by the concrete class.

# File lib/cocoapods-downloader/base.rb, line 27
def self.options
  []
end
preprocess_options(options) click to toggle source

preprocess download options

Usage of this method is optional. concrete strategies should not assume options are preprocessed for correct execution.

@param [Hash<Symbol,String>] options

The request options to preprocess

@return [Hash<Symbol,String>] the new options

# File lib/cocoapods-downloader/base.rb, line 189
def self.preprocess_options(options)
  options
end
user_agent_string(base_module = Pod) click to toggle source

Returns a User-Agent string that itentifies http network requests as originating from CocoaPods. Contains version numbers from the CocoaPods Gem and the cocoapods-downloader Gem.

@param [module] base_module The Base CocoaPods Module to retrieve the version number from. @return [String] the User-Agent string.

# File lib/cocoapods-downloader/base.rb, line 140
def self.user_agent_string(base_module = Pod)
  pods_version = base_module.const_defined?('VERSION') ? "CocoaPods/#{base_module::VERSION} " : ''
  "#{pods_version}cocoapods-downloader/#{Pod::Downloader::VERSION}"
end

Public Instance Methods

checkout_options() click to toggle source

@return [Hash{Symbol=>String}] The options that would allow to

re-download the exact files.
# File lib/cocoapods-downloader/base.rb, line 121
def checkout_options
  raise 'Abstract method'
end
download() click to toggle source

Downloads the revision specified in the option of a source. If no revision is specified it fall-back to {#download_head}.

@return [void]

# File lib/cocoapods-downloader/base.rb, line 79
def download
  validate_input
  ui_action("#{name} download") do
    target_path.mkpath
    download!
  end
end
download_head() click to toggle source

Downloads the head revision of a source.

@todo Spec for raise.

@return [void]

# File lib/cocoapods-downloader/base.rb, line 93
def download_head
  ui_action("#{name} HEAD download") do
    if head_supported?
      download_head!
    else
      raise DownloaderError, "The `#{name}` downloader does not support " \
      'the HEAD option.'
    end
  end
end
head_supported?() click to toggle source

@return [Bool] Whether the downloader supports the head download

strategy.
# File lib/cocoapods-downloader/base.rb, line 107
def head_supported?
  respond_to?(:download_head!, true)
end
name() click to toggle source

@return [String] the name of the downloader.

@example Downloader::Mercurial name

"Mercurial"
# File lib/cocoapods-downloader/base.rb, line 66
def name
  self.class.name.split('::').last
end
options_specific?() click to toggle source

@return [Bool] Whether the options provided completely identify a source

or could lead to the download of different files in future.
# File lib/cocoapods-downloader/base.rb, line 114
def options_specific?
  true
end
validate_input() click to toggle source

Provides a before-download check for safety of the options in the concrete downloader.

@return [void]

# File lib/cocoapods-downloader/base.rb, line 130
def validate_input
end