module Pod::Downloader
Constants
- VERSION
@return [String] Downloader’s version, following
[semver](http://semver.org).
Public Class Methods
downloader_class_by_key()
click to toggle source
@return [Hash{Symbol=>Class}] The concrete classes of the supported
strategies by key.
# 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)
click to toggle source
@return [Downloader::Base] A concrete downloader according to the
options.
# 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
preprocess_options(options)
click to toggle source
Have the concrete strategy preprocess options
@param [Hash<Symbol,String>] options
The request options to preprocess
@return [Hash<Symbol,String>] the new options
# 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)
click to toggle source
Identifies the concrete strategy for the given options.
@param [Hash{Symbol}] options
The options for which a strategy is needed.
@return [Symbol] The symbol associated with a concrete strategy. @return [Nil] If no suitable concrete strategy could be selected.
# 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
Private Class Methods
class_for_options(options)
click to toggle source
# 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
options_to_sym(options)
click to toggle source
# File lib/cocoapods-downloader.rb, line 81 def self.options_to_sym(options) Hash[options.map { |k, v| [k.to_sym, v] }] end