Module: Downloadable Abstract

Extended by:
T::Helpers
Includes:
Context
Included in:
Bottle, Cask::Download, Homebrew::API::Download, Homebrew::RetryableDownload, Resource, SoftwareSpec
Defined in:
downloadable.rb

Overview

This module is abstract.

Subclasses must implement the abstract methods below.

Instance Attribute Summary collapse

Instance Method Summary collapse

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:



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

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:



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

def mirrors
  @mirrors
end

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



16
17
18
# File 'downloadable.rb', line 16

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:



58
59
60
# File 'downloadable.rb', line 58

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.



63
64
65
# File 'downloadable.rb', line 63

def clear_cache
  downloader.clear_cache
end

#download_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:



129
130
131
# File 'downloadable.rb', line 129

def download_name
  @download_name ||= File.basename(determine_url.to_s)
end

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



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

def download_strategy
  @download_strategy ||= determine_url&.download_strategy
end

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

Returns:



48
49
50
# File 'downloadable.rb', line 48

def download_type
  T.must(self.class.name&.split("::")&.last).gsub(/([[:lower:]])([[:upper:]])/, '\1 \2').downcase
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.

Returns:

  • (Boolean)


53
54
55
# File 'downloadable.rb', line 53

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.



81
82
83
84
85
86
87
88
89
# File 'downloadable.rb', line 81

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.

Parameters:

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

Returns:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'downloadable.rb', line 98

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

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


37
38
39
40
41
42
# File 'downloadable.rb', line 37

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.



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

def initialize
  @mirrors = T.let([], T::Array[String])
end

#initialize_dup(other) ⇒ Object



29
30
31
32
33
34
# File 'downloadable.rb', line 29

def initialize_dup(other)
  super
  @checksum = @checksum.dup
  @mirrors = @mirrors.dup
  @version = @version.dup
end

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

This method is abstract.

Returns:



45
# File 'downloadable.rb', line 45

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

Parameters:



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

def verify_download_integrity(filename)
  if filename.file?
    ohai "Verifying checksum for '#{filename.basename}'" if verbose?
    filename.verify_checksum(checksum)
  end
rescue ChecksumMissingError
  opoo <<~EOS
    Cannot verify integrity of '#{filename.basename}'.
    No checksum was provided.
    For your reference, the checksum is:
      sha256 "#{filename.sha256}"
  EOS
end

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



68
69
70
71
72
73
# File 'downloadable.rb', line 68

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

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