Class: Pod::Downloader::Base Abstract

Inherits:
Object
  • Object
show all
Extended by:
APIExposable
Defined in:
lib/cocoapods-downloader/base.rb

Overview

This class is abstract.

Subclass and implement #download.

The base class defines the common behaviour of the downloaders.

Direct Known Subclasses

Git, Mercurial, RemoteFile, Subversion

Instance Attribute Summary collapse

Downloading collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIExposable

expose_api

Constructor Details

#initialize(target_path, url, options) ⇒ Base

Returns a new instance of Base.

Parameters:

  • target_path (String, Pathname)

    @see target_path

  • url (String)

    @see url

  • options (Hash={Symbol=>String})

    @see options



48
49
50
51
52
53
54
55
56
57
58
# 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

Instance Attribute Details

#optionsHash={Symbol=>String} (readonly)

Returns options specific to each concrete downloader.

Returns:

  • (Hash={Symbol=>String})

    options specific to each concrete downloader.



42
43
44
# File 'lib/cocoapods-downloader/base.rb', line 42

def options
  @options
end

#target_pathPathname (readonly)

Returns the destination folder for the download.

Returns:

  • (Pathname)

    the destination folder for the download.



33
34
35
# File 'lib/cocoapods-downloader/base.rb', line 33

def target_path
  @target_path
end

#urlString (readonly)

Returns the url of the remote source.

Returns:

  • (String)

    the url of the remote source.



37
38
39
# File 'lib/cocoapods-downloader/base.rb', line 37

def url
  @url
end

Class Method Details

.executable(name) ⇒ void

This method returns an undefined value.

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

Parameters:

  • name (Symbol)

    the name of the executable.



169
170
171
172
173
174
175
176
177
# 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

.optionsArray<Symbol>

This method is abstract.

Override in subclasses.

Returns the options accepted by the concrete class.

Returns:

  • (Array<Symbol>)

    the options accepted by the concrete class.



27
28
29
# File 'lib/cocoapods-downloader/base.rb', line 27

def self.options
  []
end

.preprocess_options(options) ⇒ Hash<Symbol,String>

preprocess download options

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

Parameters:

  • options (Hash<Symbol,String>)

    The request options to preprocess

Returns:

  • (Hash<Symbol,String>)

    the new options



189
190
191
# File 'lib/cocoapods-downloader/base.rb', line 189

def self.preprocess_options(options)
  options
end

.user_agent_string(base_module = Pod) ⇒ String

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.

Parameters:

  • base_module (module) (defaults to: Pod)

    The Base CocoaPods Module to retrieve the version number from.

Returns:

  • (String)

    the User-Agent string.



140
141
142
143
# 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

Instance Method Details

#checkout_optionsHash{Symbol=>String}

Returns The options that would allow to re-download the exact files.

Returns:

  • (Hash{Symbol=>String})

    The options that would allow to re-download the exact files.



121
122
123
# File 'lib/cocoapods-downloader/base.rb', line 121

def checkout_options
  raise 'Abstract method'
end

#downloadvoid

This method returns an undefined value.

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



79
80
81
82
83
84
85
# File 'lib/cocoapods-downloader/base.rb', line 79

def download
  validate_input
  ui_action("#{name} download") do
    target_path.mkpath
    download!
  end
end

#download_headvoid

TODO:

Spec for raise.

This method returns an undefined value.

Downloads the head revision of a source.



93
94
95
96
97
98
99
100
101
102
# 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?Bool

Returns Whether the downloader supports the head download strategy.

Returns:

  • (Bool)

    Whether the downloader supports the head download strategy.



107
108
109
# File 'lib/cocoapods-downloader/base.rb', line 107

def head_supported?
  respond_to?(:download_head!, true)
end

#nameString

Returns the name of the downloader.

Examples:

Downloader::Mercurial name


"Mercurial"

Returns:

  • (String)

    the name of the downloader.



66
67
68
# File 'lib/cocoapods-downloader/base.rb', line 66

def name
  self.class.name.split('::').last
end

#options_specific?Bool

Returns Whether the options provided completely identify a source or could lead to the download of different files in future.

Returns:

  • (Bool)

    Whether the options provided completely identify a source or could lead to the download of different files in future.



114
115
116
# File 'lib/cocoapods-downloader/base.rb', line 114

def options_specific?
  true
end

#validate_inputvoid

This method returns an undefined value.

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



130
131
# File 'lib/cocoapods-downloader/base.rb', line 130

def validate_input
end