Class: AbstractDownloadStrategy Abstract Private
- Extended by:
- T::Helpers
- Includes:
- Context, FileUtils, SystemCommand::Mixin, Utils::Output::Mixin
- Defined in:
- download_strategy.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Abstract superclass for all download strategies.
Direct Known Subclasses
AbstractFileDownloadStrategy, Homebrew::API::JSONDownloadStrategy, VCSDownloadStrategy
Instance Attribute Summary collapse
- #cache ⇒ Pathname readonly private
-
#url ⇒ String
readonly
The download URL.
Instance Method Summary collapse
- #basename ⇒ Pathname private
-
#cached_location ⇒ Pathname
abstract
Location of the cached download.
-
#clear_cache ⇒ void
Remove #cached_location and any other files associated with the resource from the cache.
-
#fetch(timeout: nil) ⇒ void
Download and cache the resource at #cached_location.
-
#fetched_size ⇒ Integer?
private
Total bytes downloaded if available.
- #initialize(url, name, version, **meta) ⇒ void constructor private
- #ohai(title, *sput) ⇒ void private
-
#quiet! ⇒ void
Disable any output during downloading.
- #quiet? ⇒ Boolean private
-
#source_modified_time ⇒ Time
Returns the most recent modified time for all files in the current working directory after stage.
-
#stage(&block) ⇒ void
Unpack #cached_location into the current working directory.
-
#total_size ⇒ Integer?
private
Total download size if available.
Methods included from Utils::Output::Mixin
#odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled
Methods included from SystemCommand::Mixin
#system_command, #system_command!
Methods included from Context
current, current=, #debug?, #verbose?, #with_context
Constructor Details
#initialize(url, name, version, **meta) ⇒ 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.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'download_strategy.rb', line 56 def initialize(url, name, version, **) @cached_location = T.let(nil, T.nilable(Pathname)) @ref_type = T.let(nil, T.nilable(Symbol)) @ref = T.let(nil, T.untyped) @url = url @name = name @version = version @cache = T.let(.fetch(:cache, HOMEBREW_CACHE), Pathname) @meta = T.let(, T::Hash[Symbol, T.untyped]) @quiet = T.let(false, T.nilable(T::Boolean)) end |
Instance Attribute Details
#cache ⇒ Pathname (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.
42 43 44 |
# File 'download_strategy.rb', line 42 def cache @cache end |
#url ⇒ String (readonly)
The download URL.
39 40 41 |
# File 'download_strategy.rb', line 39 def url @url end |
Instance Method Details
#basename ⇒ 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.
157 158 159 |
# File 'download_strategy.rb', line 157 def basename cached_location.basename end |
#cached_location ⇒ Pathname
Location of the cached download.
86 |
# File 'download_strategy.rb', line 86 def cached_location; end |
#clear_cache ⇒ void
This method returns an undefined value.
Remove #cached_location and any other files associated with the resource from the cache.
152 153 154 |
# File 'download_strategy.rb', line 152 def clear_cache rm_rf(cached_location) end |
#fetch(timeout: nil) ⇒ void
This method returns an undefined value.
Download and cache the resource at #cached_location.
72 |
# File 'download_strategy.rb', line 72 def fetch(timeout: nil); end |
#fetched_size ⇒ Integer?
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.
Total bytes downloaded if available.
76 |
# File 'download_strategy.rb', line 76 def fetched_size; end |
#ohai(title, *sput) ⇒ 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.
162 163 164 |
# File 'download_strategy.rb', line 162 def ohai(title, *sput) super unless quiet? end |
#quiet! ⇒ void
This method returns an undefined value.
Disable any output during downloading.
92 93 94 |
# File 'download_strategy.rb', line 92 def quiet! @quiet = T.let(true, T.nilable(T::Boolean)) end |
#quiet? ⇒ 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.
97 98 99 |
# File 'download_strategy.rb', line 97 def quiet? Context.current.quiet? || @quiet || false end |
#source_modified_time ⇒ Time
Returns the most recent modified time for all files in the current working directory after stage.
143 144 145 |
# File 'download_strategy.rb', line 143 def source_modified_time Pathname.pwd.to_enum(:find).select(&:file?).map(&:mtime).max end |
#stage(&block) ⇒ void
This method returns an undefined value.
Unpack #cached_location into the current working directory.
Additionally, if a block is given, the working directory was previously empty and a single directory is extracted from the archive, the block will be called with the working directory changed to that directory. Otherwise this method will return, or the block will be called, without changing the current working directory.
111 112 113 114 115 116 117 118 119 |
# File 'download_strategy.rb', line 111 def stage(&block) UnpackStrategy.detect(cached_location, prioritize_extension: true, ref_type: @ref_type, ref: @ref) .extract_nestedly(basename:, prioritize_extension: true, verbose: verbose? && !quiet?) chdir(&block) if block end |
#total_size ⇒ Integer?
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.
Total download size if available.
80 |
# File 'download_strategy.rb', line 80 def total_size; end |