Module: Pod::Downloader

Defined in:
lib/cocoapods-downloader.rb,
lib/cocoapods-downloader/api.rb,
lib/cocoapods-downloader/git.rb,
lib/cocoapods-downloader/scp.rb,
lib/cocoapods-downloader/base.rb,
lib/cocoapods-downloader/http.rb,
lib/cocoapods-downloader/mercurial.rb,
lib/cocoapods-downloader/subversion.rb,
lib/cocoapods-downloader/gem_version.rb,
lib/cocoapods-downloader/remote_file.rb,
lib/cocoapods-downloader/api_exposable.rb

Defined Under Namespace

Modules: API, APIExposable Classes: Base, DownloaderError, Git, Http, Mercurial, RemoteFile, Scp, Subversion

Constant Summary collapse

VERSION =

Returns Downloader’s version, following [semver](semver.org).

Returns:

  • (String)

    Downloader’s version, following [semver](semver.org).

'2.1'.freeze

Class Method Summary collapse

Class Method Details

.class_for_options(options) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/cocoapods-downloader.rb', line 85

def self.class_for_options(options)
  if options.nil? || options.empty?
    raise DownloaderError, 'No source URL provided.'
  end

  strategy = strategy_from_options(options)
  unless strategy
    raise DownloaderError, 'Unsupported download strategy ' \
      "`#{options.inspect}`."
  end

  # Explicit return for multiple params, rubocop thinks it's useless but it's not
  return strategy, downloader_class_by_key[strategy] # rubocop:disable Style/RedundantReturn
end

.downloader_class_by_keyHash{Symbol=>Class}

Returns The concrete classes of the supported strategies by key.

Returns:

  • (Hash{Symbol=>Class})

    The concrete classes of the supported strategies by key.



21
22
23
24
25
26
27
28
29
# File 'lib/cocoapods-downloader.rb', line 21

def self.downloader_class_by_key
  {
    :git  => Git,
    :hg   => Mercurial,
    :http => Http,
    :scp  => Scp,
    :svn  => Subversion,
  }
end

.for_target(target_path, options) ⇒ Downloader::Base

Returns A concrete downloader according to the options.

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cocoapods-downloader.rb', line 49

def self.for_target(target_path, options)
  options = options_to_sym(options)

  if target_path.nil?
    raise DownloaderError, 'No target path provided.'
  end

  strategy, klass = class_for_options(options)

  url = options[strategy]
  sub_options = options.dup
  sub_options.delete(strategy)

  klass.new(target_path, url, sub_options)
end

.options_to_sym(options) ⇒ Object



81
82
83
# File 'lib/cocoapods-downloader.rb', line 81

def self.options_to_sym(options)
  Hash[options.map { |k, v| [k.to_sym, v] }]
end

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

Have the concrete strategy preprocess options

Parameters:

  • options (Hash<Symbol,String>)

    The request options to preprocess

Returns:

  • (Hash<Symbol,String>)

    the new options



72
73
74
75
76
77
# File 'lib/cocoapods-downloader.rb', line 72

def self.preprocess_options(options)
  options = options_to_sym(options)

  _, klass = class_for_options(options)
  klass.preprocess_options(options)
end

.strategy_from_options(options) ⇒ Symbol, Nil

Identifies the concrete strategy for the given options.

Parameters:

  • options (Hash{Symbol})

    The options for which a strategy is needed.

Returns:

  • (Symbol)

    The symbol associated with a concrete strategy.

  • (Nil)

    If no suitable concrete strategy could be selected.



39
40
41
42
43
44
# File 'lib/cocoapods-downloader.rb', line 39

def self.strategy_from_options(options)
  common = downloader_class_by_key.keys & options.keys
  if common.count == 1
    common.first
  end
end