Class: AbstractDownloadStrategy Abstract Private

Inherits:
Object
  • Object
show all
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.

This class is abstract.

Abstract superclass for all download strategies.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Output::Mixin

#odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_deprecated, #pretty_disabled, #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.

Parameters:



55
56
57
58
59
60
61
62
63
64
65
# File 'download_strategy.rb', line 55

def initialize(url, name, version, **meta)
  @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(meta.fetch(:cache, HOMEBREW_CACHE), Pathname)
  @meta = T.let(meta, T::Hash[Symbol, T.untyped])
  @quiet = T.let(false, T.nilable(T::Boolean))
end

Instance Attribute Details

#cachePathname (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.

Returns:



41
42
43
# File 'download_strategy.rb', line 41

def cache
  @cache
end

#urlString (readonly)

The download URL.

Returns:



38
39
40
# File 'download_strategy.rb', line 38

def url
  @url
end

Instance Method Details

#basenamePathname

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.

Returns:



164
165
166
# File 'download_strategy.rb', line 164

def basename
  cached_location.basename
end

#cached_locationPathname

This method is abstract.

Location of the cached download.

Returns:



85
# File 'download_strategy.rb', line 85

def cached_location; end

#clear_cachevoid

This method returns an undefined value.

Remove #cached_location and any other files associated with the resource from the cache.



159
160
161
# File 'download_strategy.rb', line 159

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.

Parameters:

  • timeout (Float, Integer, nil) (defaults to: nil)


71
# File 'download_strategy.rb', line 71

def fetch(timeout: nil); end

#fetched_sizeInteger?

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.

Returns:



75
# File 'download_strategy.rb', line 75

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.

Parameters:

  • title (String, Exception)
  • sput (T.anything)


169
170
171
# File 'download_strategy.rb', line 169

def ohai(title, *sput)
  super unless quiet?
end

#quiet!void

This method returns an undefined value.

Disable any output during downloading.



91
92
93
# File 'download_strategy.rb', line 91

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.

Returns:

  • (Boolean)


96
97
98
# File 'download_strategy.rb', line 96

def quiet?
  Context.current.quiet? || @quiet || false
end

#source_modified_timeTime

Returns the most recent modified time for all files in the current working directory after stage.

Returns:



144
145
146
# File 'download_strategy.rb', line 144

def source_modified_time
  Pathname.pwd.to_enum(:find).select(&:file?).map(&:mtime).max
end

#source_revisionString?

Return the checked out source revision for version control downloads.

Returns:



152
# File 'download_strategy.rb', line 152

def source_revision; 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.

Parameters:

  • block (T.proc.void, nil)


110
111
112
113
114
115
116
117
118
# File 'download_strategy.rb', line 110

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_sizeInteger?

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.

Returns:



79
# File 'download_strategy.rb', line 79

def total_size; end