mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Cleanup Downloadable variables and types
This commit is contained in:
parent
3d2ab610c9
commit
35f874c036
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "downloadable"
|
require "downloadable"
|
||||||
@ -13,8 +13,10 @@ module Cask
|
|||||||
|
|
||||||
include Context
|
include Context
|
||||||
|
|
||||||
|
sig { returns(::Cask::Cask) }
|
||||||
attr_reader :cask
|
attr_reader :cask
|
||||||
|
|
||||||
|
sig { params(cask: ::Cask::Cask, quarantine: T.nilable(T::Boolean)).void }
|
||||||
def initialize(cask, quarantine: nil)
|
def initialize(cask, quarantine: nil)
|
||||||
super()
|
super()
|
||||||
|
|
||||||
@ -29,9 +31,9 @@ module Cask
|
|||||||
|
|
||||||
sig { override.returns(T.nilable(::URL)) }
|
sig { override.returns(T.nilable(::URL)) }
|
||||||
def url
|
def url
|
||||||
return if cask.url.nil?
|
return if (cask_url = cask.url).nil?
|
||||||
|
|
||||||
@url ||= ::URL.new(cask.url.to_s, cask.url.specs)
|
@url ||= ::URL.new(cask_url.to_s, cask_url.specs)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { override.returns(T.nilable(::Checksum)) }
|
sig { override.returns(T.nilable(::Checksum)) }
|
||||||
@ -70,12 +72,14 @@ module Cask
|
|||||||
downloaded_path
|
downloaded_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(timeout: T.any(Float, Integer, NilClass)).returns([T.nilable(Time), Integer]) }
|
||||||
def time_file_size(timeout: nil)
|
def time_file_size(timeout: nil)
|
||||||
raise ArgumentError, "not supported for this download strategy" unless downloader.is_a?(CurlDownloadStrategy)
|
raise ArgumentError, "not supported for this download strategy" unless downloader.is_a?(CurlDownloadStrategy)
|
||||||
|
|
||||||
T.cast(downloader, CurlDownloadStrategy).resolved_time_file_size(timeout:)
|
T.cast(downloader, CurlDownloadStrategy).resolved_time_file_size(timeout:)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Pathname) }
|
||||||
def basename
|
def basename
|
||||||
downloader.basename
|
downloader.basename
|
||||||
end
|
end
|
||||||
@ -102,6 +106,7 @@ module Cask
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
sig { params(path: Pathname).void }
|
||||||
def quarantine(path)
|
def quarantine(path)
|
||||||
return if @quarantine.nil?
|
return if @quarantine.nil?
|
||||||
return unless Quarantine.available?
|
return unless Quarantine.available?
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "url"
|
require "url"
|
||||||
@ -23,9 +23,16 @@ module Downloadable
|
|||||||
|
|
||||||
sig { void }
|
sig { void }
|
||||||
def initialize
|
def initialize
|
||||||
|
@url = T.let(nil, T.nilable(URL))
|
||||||
|
@checksum = T.let(nil, T.nilable(Checksum))
|
||||||
@mirrors = T.let([], T::Array[String])
|
@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))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(other: Object).void }
|
||||||
def initialize_dup(other)
|
def initialize_dup(other)
|
||||||
super
|
super
|
||||||
@checksum = @checksum.dup
|
@checksum = @checksum.dup
|
||||||
@ -46,7 +53,8 @@ module Downloadable
|
|||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def download_type
|
def download_type
|
||||||
T.must(self.class.name&.split("::")&.last).gsub(/([[:lower:]])([[:upper:]])/, '\1 \2').downcase
|
class_name = T.let(self.class, T::Class[Downloadable]).name&.split("::")&.last
|
||||||
|
T.must(class_name).gsub(/([[:lower:]])([[:upper:]])/, '\1 \2').downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
sig(:final) { returns(T::Boolean) }
|
sig(:final) { returns(T::Boolean) }
|
||||||
@ -72,9 +80,9 @@ module Downloadable
|
|||||||
version unless version&.null?
|
version unless version&.null?
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { overridable.returns(T.class_of(AbstractDownloadStrategy)) }
|
sig { overridable.returns(T::Class[AbstractDownloadStrategy]) }
|
||||||
def download_strategy
|
def download_strategy
|
||||||
@download_strategy ||= determine_url&.download_strategy
|
@download_strategy ||= T.must(determine_url).download_strategy
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { overridable.returns(AbstractDownloadStrategy) }
|
sig { overridable.returns(AbstractDownloadStrategy) }
|
||||||
@ -129,7 +137,7 @@ module Downloadable
|
|||||||
|
|
||||||
sig { overridable.returns(String) }
|
sig { overridable.returns(String) }
|
||||||
def download_name
|
def download_name
|
||||||
@download_name ||= File.basename(determine_url.to_s)
|
@download_name ||= File.basename(determine_url.to_s).freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -25,15 +25,19 @@ class Resource
|
|||||||
sig { params(name: T.nilable(String), block: T.nilable(T.proc.bind(Resource).void)).void }
|
sig { params(name: T.nilable(String), block: T.nilable(T.proc.bind(Resource).void)).void }
|
||||||
def initialize(name = nil, &block)
|
def initialize(name = nil, &block)
|
||||||
super()
|
super()
|
||||||
# Ensure this is synced with `initialize_dup` and `freeze` (excluding simple objects like integers and booleans)
|
# Generally ensure this is synced with `initialize_dup` and `freeze`
|
||||||
|
# (excluding simple objects like integers & booleans, weak refs like `owner` or permafrozen objects)
|
||||||
@name = name
|
@name = name
|
||||||
|
@source_modified_time = nil
|
||||||
@patches = []
|
@patches = []
|
||||||
|
@owner = nil
|
||||||
@livecheck = Livecheck.new(self)
|
@livecheck = Livecheck.new(self)
|
||||||
@livecheck_defined = false
|
@livecheck_defined = false
|
||||||
@insecure = false
|
@insecure = false
|
||||||
instance_eval(&block) if block
|
instance_eval(&block) if block
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(other: Object).void }
|
||||||
def initialize_dup(other)
|
def initialize_dup(other)
|
||||||
super
|
super
|
||||||
@name = @name.dup
|
@name = @name.dup
|
||||||
@ -108,7 +112,7 @@ class Resource
|
|||||||
current_working_directory = Pathname.pwd
|
current_working_directory = Pathname.pwd
|
||||||
stage_resource(download_name, debug_symbols:) do |staging|
|
stage_resource(download_name, debug_symbols:) do |staging|
|
||||||
downloader.stage do
|
downloader.stage do
|
||||||
@source_modified_time = downloader.source_modified_time
|
@source_modified_time = downloader.source_modified_time.freeze
|
||||||
apply_patches
|
apply_patches
|
||||||
if block_given?
|
if block_given?
|
||||||
yield ResourceStageContext.new(self, staging)
|
yield ResourceStageContext.new(self, staging)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
@ -23,7 +23,7 @@ module Homebrew
|
|||||||
super()
|
super()
|
||||||
|
|
||||||
@downloadable = downloadable
|
@downloadable = downloadable
|
||||||
@try = 0
|
@try = T.let(0, Integer)
|
||||||
@tries = tries
|
@tries = tries
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ module Homebrew
|
|||||||
sig { override.returns(T.nilable(Version)) }
|
sig { override.returns(T.nilable(Version)) }
|
||||||
def version = downloadable.version
|
def version = downloadable.version
|
||||||
|
|
||||||
sig { override.returns(T.class_of(AbstractDownloadStrategy)) }
|
sig { override.returns(T::Class[AbstractDownloadStrategy]) }
|
||||||
def download_strategy = downloadable.download_strategy
|
def download_strategy = downloadable.download_strategy
|
||||||
|
|
||||||
sig { override.returns(AbstractDownloadStrategy) }
|
sig { override.returns(AbstractDownloadStrategy) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user