Convert Downloadable to a module.
This commit is contained in:
parent
b297be77a1
commit
b6d529dab3
@ -6,13 +6,20 @@ require "downloadable"
|
|||||||
module Homebrew
|
module Homebrew
|
||||||
module API
|
module API
|
||||||
class DownloadStrategy < CurlDownloadStrategy
|
class DownloadStrategy < CurlDownloadStrategy
|
||||||
|
sig { returns(String) }
|
||||||
|
def name # rubocop:disable Lint/UselessMethodDefinition
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
sig { override.returns(Pathname) }
|
sig { override.returns(Pathname) }
|
||||||
def symlink_location
|
def symlink_location
|
||||||
cache/name
|
cache/name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Download < Downloadable
|
class Download
|
||||||
|
include Downloadable
|
||||||
|
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
@ -29,6 +36,21 @@ module Homebrew
|
|||||||
@cache = cache
|
@cache = cache
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { override.returns(API::DownloadStrategy) }
|
||||||
|
def downloader
|
||||||
|
T.cast(super, API::DownloadStrategy)
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { override.returns(String) }
|
||||||
|
def name
|
||||||
|
downloader.name
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { override.returns(String) }
|
||||||
|
def download_type
|
||||||
|
"API"
|
||||||
|
end
|
||||||
|
|
||||||
sig { override.returns(Pathname) }
|
sig { override.returns(Pathname) }
|
||||||
def cache
|
def cache
|
||||||
@cache || super
|
@cache || super
|
||||||
@ -36,7 +58,7 @@ module Homebrew
|
|||||||
|
|
||||||
sig { returns(Pathname) }
|
sig { returns(Pathname) }
|
||||||
def symlink_location
|
def symlink_location
|
||||||
T.cast(downloader, API::DownloadStrategy).symlink_location
|
downloader.symlink_location
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -8,7 +8,9 @@ require "cask/quarantine"
|
|||||||
|
|
||||||
module Cask
|
module Cask
|
||||||
# A download corresponding to a {Cask}.
|
# A download corresponding to a {Cask}.
|
||||||
class Download < Downloadable
|
class Download
|
||||||
|
include Downloadable
|
||||||
|
|
||||||
include Context
|
include Context
|
||||||
|
|
||||||
attr_reader :cask
|
attr_reader :cask
|
||||||
|
|||||||
@ -5,7 +5,7 @@ require "url"
|
|||||||
require "checksum"
|
require "checksum"
|
||||||
require "download_strategy"
|
require "download_strategy"
|
||||||
|
|
||||||
class Downloadable
|
module Downloadable
|
||||||
include Context
|
include Context
|
||||||
extend T::Helpers
|
extend T::Helpers
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ class Downloadable
|
|||||||
@version = @version.dup
|
@version = @version.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { override.returns(T.self_type) }
|
sig { returns(T.self_type) }
|
||||||
def freeze
|
def freeze
|
||||||
@checksum.freeze
|
@checksum.freeze
|
||||||
@mirrors.freeze
|
@mirrors.freeze
|
||||||
@ -40,14 +40,12 @@ class Downloadable
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { abstract.returns(String) }
|
||||||
def name
|
def name; end
|
||||||
""
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def download_type
|
def download_type
|
||||||
T.must(T.must(self.class.name).split("::").last).gsub(/([[:lower:]])([[:upper:]])/, '\1 \2').downcase
|
T.must(self.class.name&.split("::")&.last).gsub(/([[:lower:]])([[:upper:]])/, '\1 \2').downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
@ -73,16 +71,16 @@ class Downloadable
|
|||||||
version unless version&.null?
|
version unless version&.null?
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T.class_of(AbstractDownloadStrategy)) }
|
sig { overridable.returns(T.class_of(AbstractDownloadStrategy)) }
|
||||||
def download_strategy
|
def download_strategy
|
||||||
@download_strategy ||= determine_url&.download_strategy
|
@download_strategy ||= determine_url&.download_strategy
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(AbstractDownloadStrategy) }
|
sig { overridable.returns(AbstractDownloadStrategy) }
|
||||||
def downloader
|
def downloader
|
||||||
@downloader ||= begin
|
@downloader ||= begin
|
||||||
primary_url, *mirrors = determine_url_mirrors
|
primary_url, *mirrors = determine_url_mirrors
|
||||||
raise ArgumentError, "attempted to use a Downloadable without a URL!" if primary_url.blank?
|
raise ArgumentError, "attempted to use a `Downloadable` without a URL!" if primary_url.blank?
|
||||||
|
|
||||||
download_strategy.new(primary_url, download_name, version,
|
download_strategy.new(primary_url, download_name, version,
|
||||||
mirrors:, cache:, **T.must(@url).specs)
|
mirrors:, cache:, **T.must(@url).specs)
|
||||||
@ -90,7 +88,7 @@ class Downloadable
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig {
|
sig {
|
||||||
params(
|
overridable.params(
|
||||||
verify_download_integrity: T::Boolean,
|
verify_download_integrity: T::Boolean,
|
||||||
timeout: T.nilable(T.any(Integer, Float)),
|
timeout: T.nilable(T.any(Integer, Float)),
|
||||||
quiet: T::Boolean,
|
quiet: T::Boolean,
|
||||||
@ -111,7 +109,7 @@ class Downloadable
|
|||||||
download
|
download
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(filename: Pathname).void }
|
sig { overridable.params(filename: Pathname).void }
|
||||||
def verify_download_integrity(filename)
|
def verify_download_integrity(filename)
|
||||||
if filename.file?
|
if filename.file?
|
||||||
ohai "Verifying checksum for '#{filename.basename}'" if verbose?
|
ohai "Verifying checksum for '#{filename.basename}'" if verbose?
|
||||||
|
|||||||
5
Library/Homebrew/downloadable.rbi
Normal file
5
Library/Homebrew/downloadable.rbi
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# typed: strict
|
||||||
|
|
||||||
|
module Downloadable
|
||||||
|
requires_ancestor { Kernel }
|
||||||
|
end
|
||||||
@ -9,7 +9,8 @@ require "extend/on_system"
|
|||||||
# Resource is the fundamental representation of an external resource. The
|
# Resource is the fundamental representation of an external resource. The
|
||||||
# primary formula download, along with other declared resources, are instances
|
# primary formula download, along with other declared resources, are instances
|
||||||
# of this class.
|
# of this class.
|
||||||
class Resource < Downloadable
|
class Resource
|
||||||
|
include Downloadable
|
||||||
include FileUtils
|
include FileUtils
|
||||||
include OnSystem::MacOSAndLinux
|
include OnSystem::MacOSAndLinux
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,9 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
class RetryableDownload < Downloadable
|
class RetryableDownload
|
||||||
|
include Downloadable
|
||||||
|
|
||||||
sig { returns(Downloadable) }
|
sig { returns(Downloadable) }
|
||||||
attr_reader :downloadable
|
attr_reader :downloadable
|
||||||
private :downloadable
|
private :downloadable
|
||||||
|
|||||||
@ -15,7 +15,9 @@ require "compilers"
|
|||||||
require "macos_version"
|
require "macos_version"
|
||||||
require "extend/on_system"
|
require "extend/on_system"
|
||||||
|
|
||||||
class SoftwareSpec < Downloadable
|
class SoftwareSpec
|
||||||
|
include Downloadable
|
||||||
|
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
include OnSystem::MacOSAndLinux
|
include OnSystem::MacOSAndLinux
|
||||||
|
|
||||||
@ -294,7 +296,9 @@ class HeadSoftwareSpec < SoftwareSpec
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Bottle < Downloadable
|
class Bottle
|
||||||
|
include Downloadable
|
||||||
|
|
||||||
class Filename
|
class Filename
|
||||||
attr_reader :name, :version, :tag, :rebuild
|
attr_reader :name, :version, :tag, :rebuild
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user