Module: Downloadable Abstract

Overview

This module is abstract.

Subclasses must implement the abstract methods below.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#checksumChecksum? (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:



21
22
23
# File 'downloadable.rb', line 21

def checksum
  @checksum
end

#mirrorsArray<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.

Returns:



24
25
26
# File 'downloadable.rb', line 24

def mirrors
  @mirrors
end

#phaseSymbol

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:



27
28
29
# File 'downloadable.rb', line 27

def phase
  @phase
end

#urlString, ... (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:



18
19
20
# File 'downloadable.rb', line 18

def url
  @url
end

Instance Method Details

#cached_downloadPathname

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:



80
81
82
# File 'downloadable.rb', line 80

def cached_download
  downloader.cached_location
end

#clear_cachevoid

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.



85
86
87
# File 'downloadable.rb', line 85

def clear_cache
  downloader.clear_cache
end

#download_queue_nameString

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:



69
# File 'downloadable.rb', line 69

def download_queue_name = download_name

#download_queue_typeString

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 is abstract.

Returns:



72
# File 'downloadable.rb', line 72

def download_queue_type; end

#download_strategyT::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.

Returns:



110
111
112
# File 'downloadable.rb', line 110

def download_strategy
  @download_strategy ||= T.must(determine_url).download_strategy
end

#downloaded!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.



32
# File 'downloadable.rb', line 32

def downloaded! = (@phase = :downloaded)

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

Returns:

  • (Boolean)


75
76
77
# File 'downloadable.rb', line 75

def downloaded?
  cached_download.exist?
end

#downloaderAbstractDownloadStrategy

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.



115
116
117
118
119
120
121
122
123
# File 'downloadable.rb', line 115

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

#downloading!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.



30
# File 'downloadable.rb', line 30

def downloading! = (@phase = :downloading)

#extracting!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
# File 'downloadable.rb', line 38

def extracting! = (@phase = :extracting)

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

Parameters:

  • verify_download_integrity (Boolean) (defaults to: true)
  • timeout (Integer, Float, nil) (defaults to: nil)
  • quiet (Boolean) (defaults to: false)

Returns:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'downloadable.rb', line 132

def fetch(verify_download_integrity: true, timeout: nil, quiet: false)
  downloading!

  cache.mkpath

  begin
    downloader.quiet! if quiet
    downloader.fetch(timeout:)
  rescue ErrorDuringExecution, CurlDownloadStrategyError => e
    raise DownloadError.new(self, e)
  end

  downloaded!

  download = cached_download
  verify_download_integrity(download) if verify_download_integrity
  download
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:

  • (Integer, nil)


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

def fetched_size
  downloader.fetched_size
end

#freezeT.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.

Returns:

  • (T.self_type)


61
62
63
64
65
66
# File 'downloadable.rb', line 61

def freeze
  @checksum.freeze
  @mirrors.freeze
  @version.freeze
  super
end

#initializevoid

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.



41
42
43
44
45
46
47
48
49
50
# File 'downloadable.rb', line 41

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))
  @phase = T.let(:preparing, Symbol)
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.

Parameters:



53
54
55
56
57
58
# File 'downloadable.rb', line 53

def initialize_dup(other)
  super
  @checksum = @checksum.dup
  @mirrors = @mirrors.dup
  @version = @version.dup
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:

  • (Integer, nil)


97
98
99
# File 'downloadable.rb', line 97

def total_size
  @total_size ||= T.let(downloader.total_size, T.nilable(Integer))
end

#verified!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.



36
# File 'downloadable.rb', line 36

def verified! = (@phase = :verified)

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

Parameters:



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'downloadable.rb', line 152

def verify_download_integrity(filename)
  verifying!

  if filename.file?
    ohai "Verifying checksum for '#{filename.basename}'" if verbose?
    filename.verify_checksum(checksum)
    verified!
  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

#verifying!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.



34
# File 'downloadable.rb', line 34

def verifying! = (@phase = :verifying)

#versionVersion?

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:



102
103
104
105
106
107
# File 'downloadable.rb', line 102

def version
  return @version if @version && !@version.null?

  version = determine_url&.version
  version unless version&.null?
end