Class: Downloadable Abstract

Inherits:
Object show all
Extended by:
T::Helpers
Includes:
Context
Defined in:
downloadable.rb

Overview

This class is abstract.

It cannot be directly instantiated. Subclasses must implement the abstract methods below.

Direct Known Subclasses

Cask::Download, Homebrew::API::Download, Resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

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



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

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

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:



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

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:



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

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:



14
15
16
# File 'downloadable.rb', line 14

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:



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

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.



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

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:



112
113
114
# File 'downloadable.rb', line 112

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



66
67
68
# File 'downloadable.rb', line 66

def download_strategy
  @download_strategy ||= 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.

Returns:

  • (Boolean)


43
44
45
# File 'downloadable.rb', line 43

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.



71
72
73
74
75
76
77
78
79
# File 'downloadable.rb', line 71

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

Returns:



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'downloadable.rb', line 82

def fetch(verify_download_integrity: true, timeout: nil)
  cache.mkpath

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


35
36
37
38
39
40
# File 'downloadable.rb', line 35

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

#initialize_dup(other) ⇒ Object



27
28
29
30
31
32
# File 'downloadable.rb', line 27

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.

Parameters:



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

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:



58
59
60
61
62
63
# File 'downloadable.rb', line 58

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

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