Allow symbol keys for tab attributes

This commit is contained in:
Douglas Eichelberger 2025-09-07 14:58:11 -07:00
parent 383159cb47
commit 592ee2c973
No known key found for this signature in database
GPG Key ID: F90193CBD547EB81
6 changed files with 27 additions and 26 deletions

View File

@ -11,7 +11,7 @@ module Cask
sig { returns(T.nilable(T::Array[T.untyped])) } sig { returns(T.nilable(T::Array[T.untyped])) }
attr_accessor :uninstall_artifacts attr_accessor :uninstall_artifacts
sig { params(attributes: T::Hash[String, T.untyped]).void } sig { params(attributes: T::Hash[T.any(String, Symbol), T.untyped]).void }
def initialize(attributes = {}) def initialize(attributes = {})
@uninstall_flight_blocks = T.let(nil, T.nilable(T::Boolean)) @uninstall_flight_blocks = T.let(nil, T.nilable(T::Boolean))
@uninstall_artifacts = T.let(nil, T.nilable(T::Array[T.untyped])) @uninstall_artifacts = T.let(nil, T.nilable(T::Array[T.untyped]))

View File

@ -80,7 +80,8 @@ module Cask
specs[:revisions] = @revisions = T.let(revisions, T.nilable(T::Hash[T.any(Symbol, String), String])) specs[:revisions] = @revisions = T.let(revisions, T.nilable(T::Hash[T.any(Symbol, String), String]))
specs[:revision] = @revision = T.let(revision, T.nilable(String)) specs[:revision] = @revision = T.let(revision, T.nilable(String))
specs[:trust_cert] = @trust_cert = T.let(trust_cert, T.nilable(T::Boolean)) specs[:trust_cert] = @trust_cert = T.let(trust_cert, T.nilable(T::Boolean))
specs[:cookies] = @cookies = T.let(cookies, T.nilable(T::Hash[T.any(String, Symbol), String])) specs[:cookies] =
@cookies = T.let(cookies&.transform_keys(&:to_s), T.nilable(T::Hash[String, String]))
specs[:referer] = @referer = T.let(referer, T.nilable(T.any(URI::Generic, String))) specs[:referer] = @referer = T.let(referer, T.nilable(T.any(URI::Generic, String)))
specs[:headers] = @header = T.let(header, T.nilable(T.any(String, T::Array[String]))) specs[:headers] = @header = T.let(header, T.nilable(T.any(String, T::Array[String])))
specs[:user_agent] = @user_agent = T.let(user_agent || :default, T.nilable(T.any(Symbol, String))) specs[:user_agent] = @user_agent = T.let(user_agent || :default, T.nilable(T.any(Symbol, String)))

View File

@ -169,7 +169,7 @@ class SystemCommand
args: T::Array[T.any(String, Integer, Float, Pathname, URI::Generic)], args: T::Array[T.any(String, Integer, Float, Pathname, URI::Generic)],
sudo: T::Boolean, sudo: T::Boolean,
sudo_as_root: T::Boolean, sudo_as_root: T::Boolean,
env: T::Hash[String, String], env: T::Hash[String, T.nilable(String)],
input: T.any(String, T::Array[String]), input: T.any(String, T::Array[String]),
must_succeed: T::Boolean, must_succeed: T::Boolean,
print_stdout: T.any(T::Boolean, Symbol), print_stdout: T.any(T::Boolean, Symbol),

View File

@ -38,7 +38,7 @@ class AbstractTab
# @api internal # @api internal
attr_accessor :runtime_dependencies attr_accessor :runtime_dependencies
sig { params(attributes: T::Hash[String, T.untyped]).void } sig { params(attributes: T::Hash[T.any(String, Symbol), T.untyped]).void }
def initialize(attributes = {}) def initialize(attributes = {})
@installed_as_dependency = T.let(nil, T.nilable(T::Boolean)) @installed_as_dependency = T.let(nil, T.nilable(T::Boolean))
@installed_on_request = T.let(nil, T.nilable(T::Boolean)) @installed_on_request = T.let(nil, T.nilable(T::Boolean))
@ -170,7 +170,7 @@ class Tab < AbstractTab
attr_writer :used_options, :unused_options, :compiler, :source_modified_time attr_writer :used_options, :unused_options, :compiler, :source_modified_time
attr_reader :tapped_from attr_reader :tapped_from
sig { params(attributes: T::Hash[String, T.untyped]).void } sig { params(attributes: T::Hash[T.any(String, Symbol), T.untyped]).void }
def initialize(attributes = {}) def initialize(attributes = {})
@poured_from_bottle = T.let(nil, T.nilable(T::Boolean)) @poured_from_bottle = T.let(nil, T.nilable(T::Boolean))
@built_as_bottle = T.let(nil, T.nilable(T::Boolean)) @built_as_bottle = T.let(nil, T.nilable(T::Boolean))

View File

@ -185,7 +185,7 @@ RSpec.describe Formula do
build_values_with_no_installed_alias = [ build_values_with_no_installed_alias = [
BuildOptions.new(Options.new, f.options), BuildOptions.new(Options.new, f.options),
Tab.new("source" => { "path" => f.path.to_s }), Tab.new(source: { "path" => f.path.to_s }),
] ]
build_values_with_no_installed_alias.each do |build| build_values_with_no_installed_alias.each do |build|
f.build = build f.build = build
@ -201,7 +201,7 @@ RSpec.describe Formula do
CoreTap.instance.alias_dir.mkpath CoreTap.instance.alias_dir.mkpath
FileUtils.ln_sf f.path, alias_path FileUtils.ln_sf f.path, alias_path
f.build = Tab.new("source" => { "path" => alias_path.to_s }) f.build = Tab.new(source: { "path" => alias_path.to_s })
expect(f.installed_alias_path).to eq(alias_path) expect(f.installed_alias_path).to eq(alias_path)
expect(f.installed_alias_name).to eq(alias_name) expect(f.installed_alias_name).to eq(alias_name)
@ -220,7 +220,7 @@ RSpec.describe Formula do
build_values_with_no_installed_alias = [ build_values_with_no_installed_alias = [
BuildOptions.new(Options.new, f.options), BuildOptions.new(Options.new, f.options),
Tab.new("source" => { "path" => f.path.to_s }), Tab.new(source: { "path" => f.path.to_s }),
] ]
build_values_with_no_installed_alias.each do |build| build_values_with_no_installed_alias.each do |build|
f.build = build f.build = build
@ -237,7 +237,7 @@ RSpec.describe Formula do
tap.alias_dir.mkpath tap.alias_dir.mkpath
FileUtils.ln_sf f.path, alias_path FileUtils.ln_sf f.path, alias_path
f.build = Tab.new("source" => { "path" => alias_path.to_s }) f.build = Tab.new(source: { "path" => alias_path.to_s })
expect(f.installed_alias_path).to eq(alias_path) expect(f.installed_alias_path).to eq(alias_path)
expect(f.installed_alias_name).to eq(alias_name) expect(f.installed_alias_name).to eq(alias_name)
@ -440,7 +440,7 @@ RSpec.describe Formula do
f = formula(alias_path:) do f = formula(alias_path:) do
url "foo-1.0" url "foo-1.0"
end end
f.build = Tab.new("source" => { "path" => source_path.to_s }) f.build = Tab.new(source: { "path" => source_path.to_s })
expect(f.alias_path).to eq(alias_path) expect(f.alias_path).to eq(alias_path)
expect(f.installed_alias_path).to be_nil expect(f.installed_alias_path).to be_nil
@ -453,7 +453,7 @@ RSpec.describe Formula do
f = formula(alias_path:) do f = formula(alias_path:) do
url "foo-1.0" url "foo-1.0"
end end
f.build = Tab.new("source" => { "path" => source_path.to_s }) f.build = Tab.new(source: { "path" => source_path.to_s })
CoreTap.instance.alias_dir.mkpath CoreTap.instance.alias_dir.mkpath
FileUtils.ln_sf f.path, source_path FileUtils.ln_sf f.path, source_path
@ -919,7 +919,7 @@ RSpec.describe Formula do
f1 = formula "f1" do f1 = formula "f1" do
url "f1-1" url "f1-1"
depends_on xcode: ["1.0", "optional"] depends_on xcode: ["1.0", :optional]
end end
stub_formula_loader(f1) stub_formula_loader(f1)

View File

@ -116,7 +116,7 @@ RSpec.describe Tab do
tab = described_class.new tab = described_class.new
expect(tab.parsed_homebrew_version).to be Version::NULL expect(tab.parsed_homebrew_version).to be Version::NULL
tab = described_class.new("homebrew_version" => "1.2.3") tab = described_class.new(homebrew_version: "1.2.3")
expect(tab.parsed_homebrew_version).to eq("1.2.3") expect(tab.parsed_homebrew_version).to eq("1.2.3")
expect(tab.parsed_homebrew_version).to be < "1.2.3-1-g12789abdf" expect(tab.parsed_homebrew_version).to be < "1.2.3-1-g12789abdf"
expect(tab.parsed_homebrew_version).to be_a(Version) expect(tab.parsed_homebrew_version).to be_a(Version)
@ -126,7 +126,7 @@ RSpec.describe Tab do
expect(tab.parsed_homebrew_version).to be > "1.2.4-566-g21789abdf" expect(tab.parsed_homebrew_version).to be > "1.2.4-566-g21789abdf"
expect(tab.parsed_homebrew_version).to be < "1.2.4-568-g01789abdf" expect(tab.parsed_homebrew_version).to be < "1.2.4-568-g01789abdf"
tab = described_class.new("homebrew_version" => "2.0.0-134-gabcdefabc-dirty") tab = described_class.new(homebrew_version: "2.0.0-134-gabcdefabc-dirty")
expect(tab.parsed_homebrew_version).to be > "2.0.0" expect(tab.parsed_homebrew_version).to be > "2.0.0"
expect(tab.parsed_homebrew_version).to be > "2.0.0-133-g21789abdf" expect(tab.parsed_homebrew_version).to be > "2.0.0-133-g21789abdf"
expect(tab.parsed_homebrew_version).to be < "2.0.0-135-g01789abdf" expect(tab.parsed_homebrew_version).to be < "2.0.0-135-g01789abdf"
@ -486,10 +486,10 @@ RSpec.describe Tab do
it "returns install information for the Tab" do it "returns install information for the Tab" do
tab = described_class.new( tab = described_class.new(
"poured_from_bottle" => true, poured_from_bottle: true,
"loaded_from_api" => true, loaded_from_api: true,
"time" => 1_720_189_863, time: 1_720_189_863,
"used_options" => %w[--with-foo --without-bar], used_options: %w[--with-foo --without-bar],
) )
output = "Poured from bottle using the formulae.brew.sh API on #{time_string} " \ output = "Poured from bottle using the formulae.brew.sh API on #{time_string} " \
"with: --with-foo --without-bar" "with: --with-foo --without-bar"
@ -497,42 +497,42 @@ RSpec.describe Tab do
end end
it "includes 'Poured from bottle' if the formula was installed from a bottle" do it "includes 'Poured from bottle' if the formula was installed from a bottle" do
tab = described_class.new("poured_from_bottle" => true) tab = described_class.new(poured_from_bottle: true)
expect(tab.to_s).to include("Poured from bottle") expect(tab.to_s).to include("Poured from bottle")
end end
it "includes 'Built from source' if the formula was not installed from a bottle" do it "includes 'Built from source' if the formula was not installed from a bottle" do
tab = described_class.new("poured_from_bottle" => false) tab = described_class.new(poured_from_bottle: false)
expect(tab.to_s).to include("Built from source") expect(tab.to_s).to include("Built from source")
end end
it "includes 'using the formulae.brew.sh API' if the formula was installed from the API" do it "includes 'using the formulae.brew.sh API' if the formula was installed from the API" do
tab = described_class.new("loaded_from_api" => true) tab = described_class.new(loaded_from_api: true)
expect(tab.to_s).to include("using the formulae.brew.sh API") expect(tab.to_s).to include("using the formulae.brew.sh API")
end end
it "does not include 'using the formulae.brew.sh API' if the formula was not installed from the API" do it "does not include 'using the formulae.brew.sh API' if the formula was not installed from the API" do
tab = described_class.new("loaded_from_api" => false) tab = described_class.new(loaded_from_api: false)
expect(tab.to_s).not_to include("using the formulae.brew.sh API") expect(tab.to_s).not_to include("using the formulae.brew.sh API")
end end
it "includes the time value if specified" do it "includes the time value if specified" do
tab = described_class.new("time" => 1_720_189_863) tab = described_class.new(time: 1_720_189_863)
expect(tab.to_s).to include("on #{time_string}") expect(tab.to_s).to include("on #{time_string}")
end end
it "does not include the time value if not specified" do it "does not include the time value if not specified" do
tab = described_class.new("time" => nil) tab = described_class.new(time: nil)
expect(tab.to_s).not_to match(/on %d+-%d+-%d+ at %d+:%d+:%d+/) expect(tab.to_s).not_to match(/on %d+-%d+-%d+ at %d+:%d+:%d+/)
end end
it "includes options if specified" do it "includes options if specified" do
tab = described_class.new("used_options" => %w[--with-foo --without-bar]) tab = described_class.new(used_options: %w[--with-foo --without-bar])
expect(tab.to_s).to include("with: --with-foo --without-bar") expect(tab.to_s).to include("with: --with-foo --without-bar")
end end
it "not to include options if not specified" do it "not to include options if not specified" do
tab = described_class.new("used_options" => []) tab = described_class.new(used_options: [])
expect(tab.to_s).not_to include("with: ") expect(tab.to_s).not_to include("with: ")
end end
end end