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/bazaar.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, Bazaar, DownloaderError, Git, Http, Mercurial, RemoteFile, Scp, Subversion

Constant Summary collapse

VERSION =
'1.3.0'.freeze

Class Method Summary collapse

Class Method Details

.class_for_options(options) ⇒ Object


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

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}


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

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

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


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

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


83
84
85
# File 'lib/cocoapods-downloader.rb', line 83

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


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

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.


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

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