Incorporate feedback

This commit is contained in:
Douglas Eichelberger 2025-03-13 10:26:41 -07:00
parent f183d0a398
commit c48870080e
No known key found for this signature in database
GPG Key ID: F90193CBD547EB81
6 changed files with 27 additions and 26 deletions

View File

@ -5,12 +5,12 @@ require "source_location"
require "utils/curl"
module Cask
BlockReturn = T.type_alias do
T.any(URI::Generic, String, [T.any(URI::Generic, String), T::Hash[Symbol, T.untyped]])
end
# Class corresponding to the `url` stanza.
class URL < SimpleDelegator
BlockReturn = T.type_alias do
T.any(URI::Generic, String, [T.any(URI::Generic, String), T::Hash[Symbol, T.untyped]])
end
class DSL
sig { returns(T.any(URI::Generic, String)) }
attr_reader :uri
@ -173,9 +173,8 @@ module Cask
#
# @api public
sig {
override
.params(method: Symbol, args: T.untyped, block: T.nilable(T.proc.returns(T.untyped)))
.returns(T.untyped)
override.params(method: Symbol, args: T.untyped, block: T.nilable(T.proc.returns(T.untyped)))
.returns(T.anything)
}
def method_missing(method, *args, &block)
if @dsl.respond_to?(method)

View File

@ -115,7 +115,7 @@ module Homebrew
strategy = DownloadStrategyDetector.detect(url)
downloader = strategy.new(url, token, version.to_s, cache: Cask::Cache.path)
downloader.fetch
downloader.cached_location!.sha256
downloader.cached_location.sha256
end
[url.gsub(version.to_s, "\#{version}"), sha256]

View File

@ -50,12 +50,6 @@ class AbstractDownloadStrategy
sig { returns(String) }
attr_reader :url
# Location of the cached download.
#
# @api public
sig { returns(T.nilable(Pathname)) }
attr_reader :cached_location
sig { returns(Pathname) }
attr_reader :cache
@ -90,8 +84,11 @@ class AbstractDownloadStrategy
sig { overridable.params(timeout: T.any(Float, Integer, NilClass)).void }
def fetch(timeout: nil); end
sig { returns(Pathname) }
def cached_location! = T.must(cached_location)
# Location of the cached download.
#
# @api public
sig { abstract.returns(Pathname) }
def cached_location; end
# Disable any output during downloading.
#
@ -117,7 +114,7 @@ class AbstractDownloadStrategy
# @api public
sig { overridable.params(block: T.untyped).void }
def stage(&block)
UnpackStrategy.detect(cached_location!,
UnpackStrategy.detect(cached_location,
prioritize_extension: true,
ref_type: @ref_type, ref: @ref)
.extract_nestedly(basename:,
@ -158,12 +155,12 @@ class AbstractDownloadStrategy
# @api public
sig { overridable.void }
def clear_cache
rm_rf(cached_location!)
rm_rf(cached_location)
end
sig { returns(Pathname) }
def basename
cached_location!.basename
cached_location.basename
end
private
@ -212,7 +209,7 @@ end
class VCSDownloadStrategy < AbstractDownloadStrategy
abstract!
sig { returns(Pathname) }
sig { override.returns(Pathname) }
attr_reader :cached_location
REF_TYPES = [:tag, :branch, :revisions, :revision].freeze
@ -336,7 +333,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy
# Path for storing the completed download.
#
# @api public
sig { returns(Pathname) }
sig { override.returns(Pathname) }
def cached_location
return @cached_location if @cached_location

View File

@ -56,7 +56,7 @@ module Downloadable
sig { overridable.returns(Pathname) }
def cached_download
downloader.cached_location!
downloader.cached_location
end
sig { overridable.void }

View File

@ -124,8 +124,10 @@ RSpec.describe Cask::Tab, :cask do
specify "with all types of dependencies" do
cask = Cask::CaskLoader.load("with-depends-on-everything")
unar = instance_double(Formula, full_name: "unar", version: "1.2", revision: 0, pkg_version: "1.2",
deps: [], requirements: [])
unar = Class.new(Formula) do
url "my_url"
version "1.2"
end.new("unar", Pathname.new(__FILE__).expand_path, :stable)
expect(Formulary).to receive(:factory).with("unar").and_return(unar)
expected_hash = {

View File

@ -27,14 +27,15 @@ module Utils
packages.each do |cask_or_formula|
next if accumulator.key?(cask_or_formula)
if cask_or_formula.is_a?(Cask::Cask)
case cask_or_formula
when Cask::Cask
formula_deps = cask_or_formula.depends_on
.formula
.map { |f| Formula[f] }
cask_deps = cask_or_formula.depends_on
.cask
.map { |c| Cask::CaskLoader.load(c, config: nil) }
else
when Formula
formula_deps = cask_or_formula.deps
.reject(&:build?)
.reject(&:test?)
@ -42,6 +43,8 @@ module Utils
cask_deps = cask_or_formula.requirements
.filter_map(&:cask)
.map { |c| Cask::CaskLoader.load(c, config: nil) }
else
T.absurd(cask_or_formula)
end
accumulator[cask_or_formula] = formula_deps + cask_deps