class Pod::Downloader::Base
The base class defines the common behaviour of the downloaders.
@abstract Subclass and implement {#download}.
@private
Attributes
@return [Hash={Symbol=>String}] options specific to each concrete
downloader.
@return [Pathname] the destination folder for the download.
@return [String] the url of the remote source.
Public Class Methods
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
@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
@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 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
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
@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
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
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
@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
@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
@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
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