Class: Pod::Downloader::Base Abstract
- Inherits:
-
Object
- Object
- Pod::Downloader::Base
- Extended by:
- APIExposable
- Defined in:
- lib/cocoapods-downloader/base.rb
Overview
Subclass and implement #download.
The base class defines the common behaviour of the downloaders.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Hash={Symbol=>String}
readonly
Options specific to each concrete downloader.
-
#target_path ⇒ Pathname
readonly
The destination folder for the download.
-
#url ⇒ String
readonly
The url of the remote source.
Downloading collapse
-
.executable(name) ⇒ void
Defines two methods for an executable, based on its name.
-
.preprocess_options(options) ⇒ Hash<Symbol,String>
preprocess download options.
-
.user_agent_string(base_module = Pod) ⇒ String
Returns a User-Agent string that itentifies http network requests as originating from CocoaPods.
-
#checkout_options ⇒ Hash{Symbol=>String}
The options that would allow to re-download the exact files.
-
#download ⇒ void
Downloads the revision specified in the option of a source.
-
#download_head ⇒ void
Downloads the head revision of a source.
-
#head_supported? ⇒ Bool
Whether the downloader supports the head download strategy.
-
#options_specific? ⇒ Bool
Whether the options provided completely identify a source or could lead to the download of different files in future.
-
#validate_input ⇒ void
Provides a before-download check for safety of the options in the concrete downloader.
Class Method Summary collapse
-
.options ⇒ Array<Symbol>
abstract
The options accepted by the concrete class.
Instance Method Summary collapse
-
#initialize(target_path, url, options) ⇒ Base
constructor
A new instance of Base.
-
#name ⇒ String
The name of the downloader.
Methods included from APIExposable
Constructor Details
#initialize(target_path, url, options) ⇒ Base
Returns a new instance of Base.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cocoapods-downloader/base.rb', line 48 def initialize(target_path, url, ) require 'pathname' @target_path = Pathname.new(target_path) @url = url @options = = .keys - self.class. unless .empty? raise DownloaderError, "Unrecognized options `#{}`" end end |
Instance Attribute Details
#options ⇒ Hash={Symbol=>String} (readonly)
Returns options specific to each concrete downloader.
42 43 44 |
# File 'lib/cocoapods-downloader/base.rb', line 42 def @options end |
#target_path ⇒ Pathname (readonly)
Returns the destination folder for the download.
33 34 35 |
# File 'lib/cocoapods-downloader/base.rb', line 33 def target_path @target_path end |
#url ⇒ String (readonly)
Returns 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
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 |
.options ⇒ Array<Symbol>
Override in subclasses.
Returns the options accepted by the concrete class.
27 28 29 |
# File 'lib/cocoapods-downloader/base.rb', line 27 def self. [] 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.
189 190 191 |
# File 'lib/cocoapods-downloader/base.rb', line 189 def self.() 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.
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_options ⇒ Hash{Symbol=>String}
Returns The options that would allow to re-download the exact files.
121 122 123 |
# File 'lib/cocoapods-downloader/base.rb', line 121 def raise 'Abstract method' end |
#download ⇒ void
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_head ⇒ void
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.
107 108 109 |
# File 'lib/cocoapods-downloader/base.rb', line 107 def head_supported? respond_to?(:download_head!, true) end |
#name ⇒ String
Returns 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.
114 115 116 |
# File 'lib/cocoapods-downloader/base.rb', line 114 def true end |
#validate_input ⇒ void
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 |