Module: Downloadable Abstract
- Extended by:
- T::Helpers
- Includes:
- Context, Utils::Output::Mixin
- Included in:
- Bottle, Cask::Download, Homebrew::API::JSONDownload, Homebrew::API::SourceDownload, Homebrew::RetryableDownload, Resource, SoftwareSpec
- Defined in:
- downloadable.rb
Overview
Subclasses must implement the abstract
methods below.
Instance Attribute Summary collapse
- #checksum ⇒ Checksum? readonly private
- #mirrors ⇒ Array<String> readonly private
- #url ⇒ nil, ... readonly private
Instance Method Summary collapse
- #cached_download ⇒ Pathname private
- #clear_cache ⇒ void private
- #download_queue_name ⇒ String private
- #download_queue_type ⇒ String abstract private
- #download_strategy ⇒ T::Class[AbstractDownloadStrategy] private
- #downloaded? ⇒ Boolean private
- #downloader ⇒ AbstractDownloadStrategy private
- #fetch(verify_download_integrity: true, timeout: nil, quiet: false) ⇒ Pathname private
- #freeze ⇒ T.self_type private
- #initialize ⇒ void private
- #initialize_dup(other) ⇒ void private
- #verify_download_integrity(filename) ⇒ void private
- #version ⇒ Version? private
Methods included from Utils::Output::Mixin
#odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled
Methods included from Context
current, current=, #debug?, #quiet?, #verbose?, #with_context
Instance Attribute Details
#checksum ⇒ Checksum? (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
21 22 23 |
# File 'downloadable.rb', line 21 def checksum @checksum end |
#mirrors ⇒ Array<String> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
24 25 26 |
# File 'downloadable.rb', line 24 def mirrors @mirrors end |
#url ⇒ nil, ... (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
18 19 20 |
# File 'downloadable.rb', line 18 def url @url end |
Instance Method Details
#cached_download ⇒ Pathname
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
65 66 67 |
# File 'downloadable.rb', line 65 def cached_download downloader.cached_location end |
#clear_cache ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
70 71 72 |
# File 'downloadable.rb', line 70 def clear_cache downloader.clear_cache end |
#download_queue_name ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
54 |
# File 'downloadable.rb', line 54 def download_queue_name = download_name |
#download_queue_type ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
57 |
# File 'downloadable.rb', line 57 def download_queue_type; end |
#download_strategy ⇒ T::Class[AbstractDownloadStrategy]
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
83 84 85 |
# File 'downloadable.rb', line 83 def download_strategy @download_strategy ||= T.must(determine_url).download_strategy end |
#downloaded? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
60 61 62 |
# File 'downloadable.rb', line 60 def downloaded? cached_download.exist? end |
#downloader ⇒ AbstractDownloadStrategy
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
88 89 90 91 92 93 94 95 96 |
# File 'downloadable.rb', line 88 def downloader @downloader ||= begin primary_url, *mirrors = determine_url_mirrors raise ArgumentError, "attempted to use a `Downloadable` without a URL!" if primary_url.blank? download_strategy.new(primary_url, download_name, version, mirrors:, cache:, **T.must(@url).specs) end end |
#fetch(verify_download_integrity: true, timeout: nil, quiet: false) ⇒ Pathname
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'downloadable.rb', line 105 def fetch(verify_download_integrity: true, timeout: nil, quiet: false) cache.mkpath begin downloader.quiet! if quiet downloader.fetch(timeout:) rescue ErrorDuringExecution, CurlDownloadStrategyError => e raise DownloadError.new(self, e) end download = cached_download verify_download_integrity(download) if verify_download_integrity download end |
#freeze ⇒ T.self_type
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
46 47 48 49 50 51 |
# File 'downloadable.rb', line 46 def freeze @checksum.freeze @mirrors.freeze @version.freeze super end |
#initialize ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
27 28 29 30 31 32 33 34 35 |
# File 'downloadable.rb', line 27 def initialize @url = T.let(nil, T.nilable(URL)) @checksum = T.let(nil, T.nilable(Checksum)) @mirrors = T.let([], T::Array[String]) @version = T.let(nil, T.nilable(Version)) @download_strategy = T.let(nil, T.nilable(T::Class[AbstractDownloadStrategy])) @downloader = T.let(nil, T.nilable(AbstractDownloadStrategy)) @download_name = T.let(nil, T.nilable(String)) end |
#initialize_dup(other) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
38 39 40 41 42 43 |
# File 'downloadable.rb', line 38 def initialize_dup(other) super @checksum = @checksum.dup @mirrors = @mirrors.dup @version = @version.dup end |
#verify_download_integrity(filename) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'downloadable.rb', line 121 def verify_download_integrity(filename) if filename.file? ohai "Verifying checksum for '#{filename.basename}'" if verbose? filename.verify_checksum(checksum) end rescue ChecksumMissingError return if silence_checksum_missing_error? opoo <<~EOS Cannot verify integrity of '#{filename.basename}'. No checksum was provided. For your reference, the checksum is: sha256 "#{filename.sha256}" EOS end |
#version ⇒ Version?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
75 76 77 78 79 80 |
# File 'downloadable.rb', line 75 def version return @version if @version && !@version.null? version = determine_url&.version version unless version&.null? end |