From 516c61057bee72b9a04da3dee743f9147f0981d0 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sun, 19 Mar 2023 17:31:51 -0700 Subject: [PATCH 1/2] Use ActiveSupport Hash#assert_valid_keys instend of refinement --- Library/Homebrew/cask/artifact/abstract_uninstall.rb | 2 +- Library/Homebrew/cask/artifact/installer.rb | 2 +- Library/Homebrew/cask/artifact/pkg.rb | 2 +- Library/Homebrew/cask/artifact/relocated.rb | 2 +- Library/Homebrew/cask/config.rb | 4 ++-- Library/Homebrew/cask/dsl/conflicts_with.rb | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index 2635bd79d1..aa1261e5ff 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -38,7 +38,7 @@ module Cask attr_reader :directives def initialize(cask, directives) - directives.assert_valid_keys!(*ORDERED_DIRECTIVES) + directives.assert_valid_keys(*ORDERED_DIRECTIVES) super(cask, **directives) directives[:signal] = Array(directives[:signal]).flatten.each_slice(2).to_a diff --git a/Library/Homebrew/cask/artifact/installer.rb b/Library/Homebrew/cask/artifact/installer.rb index ef20cd0bd1..08b34a46f6 100644 --- a/Library/Homebrew/cask/artifact/installer.rb +++ b/Library/Homebrew/cask/artifact/installer.rb @@ -67,7 +67,7 @@ module Cask ) end - args.assert_valid_keys!(*VALID_KEYS) + args.assert_valid_keys(*VALID_KEYS) new(cask, **args) end diff --git a/Library/Homebrew/cask/artifact/pkg.rb b/Library/Homebrew/cask/artifact/pkg.rb index 924f731ae4..4c79bcb385 100644 --- a/Library/Homebrew/cask/artifact/pkg.rb +++ b/Library/Homebrew/cask/artifact/pkg.rb @@ -18,7 +18,7 @@ module Cask attr_reader :path, :stanza_options def self.from_args(cask, path, **stanza_options) - stanza_options.assert_valid_keys!(:allow_untrusted, :choices) + stanza_options.assert_valid_keys(:allow_untrusted, :choices) new(cask, path, **stanza_options) end diff --git a/Library/Homebrew/cask/artifact/relocated.rb b/Library/Homebrew/cask/artifact/relocated.rb index ee5ca48d73..3c3aff2950 100644 --- a/Library/Homebrew/cask/artifact/relocated.rb +++ b/Library/Homebrew/cask/artifact/relocated.rb @@ -20,7 +20,7 @@ module Cask if target_hash raise CaskInvalidError unless target_hash.respond_to?(:keys) - target_hash.assert_valid_keys!(:target) + target_hash.assert_valid_keys(:target) end target_hash ||= {} diff --git a/Library/Homebrew/cask/config.rb b/Library/Homebrew/cask/config.rb index c99ac319da..f1238a3e10 100644 --- a/Library/Homebrew/cask/config.rb +++ b/Library/Homebrew/cask/config.rb @@ -110,8 +110,8 @@ module Cask return end - @env&.assert_valid_keys!(*self.class.defaults.keys) - @explicit.assert_valid_keys!(*self.class.defaults.keys) + @env&.assert_valid_keys(*self.class.defaults.keys) + @explicit.assert_valid_keys(*self.class.defaults.keys) end sig { returns(T::Hash[Symbol, T.any(String, Pathname, T::Array[String])]) } diff --git a/Library/Homebrew/cask/dsl/conflicts_with.rb b/Library/Homebrew/cask/dsl/conflicts_with.rb index 99ca4c9838..96993ca36b 100644 --- a/Library/Homebrew/cask/dsl/conflicts_with.rb +++ b/Library/Homebrew/cask/dsl/conflicts_with.rb @@ -22,7 +22,7 @@ module Cask ].freeze def initialize(**options) - options.assert_valid_keys!(*VALID_KEYS) + options.assert_valid_keys(*VALID_KEYS) conflicts = options.transform_values { |v| Set.new(Kernel.Array(v)) } conflicts.default = Set.new From 4dcd5ac47f49844476410969aca9296d3523b7a0 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sun, 19 Mar 2023 17:34:49 -0700 Subject: [PATCH 2/2] Remove HashValidator --- .../Homebrew/cask/artifact/abstract_uninstall.rb | 2 -- Library/Homebrew/cask/artifact/artifact.rb | 3 --- Library/Homebrew/cask/artifact/installer.rb | 3 --- Library/Homebrew/cask/artifact/pkg.rb | 3 --- Library/Homebrew/cask/artifact/relocated.rb | 3 --- Library/Homebrew/cask/config.rb | 3 --- Library/Homebrew/cask/dsl/conflicts_with.rb | 3 --- Library/Homebrew/extend/hash_validator.rb | 13 ------------- Library/Homebrew/extend/hash_validator.rbi | 6 ------ Library/Homebrew/system_command.rb | 1 - 10 files changed, 40 deletions(-) delete mode 100644 Library/Homebrew/extend/hash_validator.rb delete mode 100644 Library/Homebrew/extend/hash_validator.rbi diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index aa1261e5ff..7b4d522a7a 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -6,8 +6,6 @@ require "timeout" require "utils/user" require "cask/artifact/abstract_artifact" require "cask/pkg" -require "extend/hash_validator" -using HashValidator module Cask module Artifact diff --git a/Library/Homebrew/cask/artifact/artifact.rb b/Library/Homebrew/cask/artifact/artifact.rb index 705cc4d18a..a3b25a5972 100644 --- a/Library/Homebrew/cask/artifact/artifact.rb +++ b/Library/Homebrew/cask/artifact/artifact.rb @@ -3,9 +3,6 @@ require "cask/artifact/moved" -require "extend/hash_validator" -using HashValidator - module Cask module Artifact # Generic artifact corresponding to the `artifact` stanza. diff --git a/Library/Homebrew/cask/artifact/installer.rb b/Library/Homebrew/cask/artifact/installer.rb index 08b34a46f6..735a74688f 100644 --- a/Library/Homebrew/cask/artifact/installer.rb +++ b/Library/Homebrew/cask/artifact/installer.rb @@ -3,9 +3,6 @@ require "cask/artifact/abstract_artifact" -require "extend/hash_validator" -using HashValidator - module Cask module Artifact # Artifact corresponding to the `installer` stanza. diff --git a/Library/Homebrew/cask/artifact/pkg.rb b/Library/Homebrew/cask/artifact/pkg.rb index 4c79bcb385..7a22057909 100644 --- a/Library/Homebrew/cask/artifact/pkg.rb +++ b/Library/Homebrew/cask/artifact/pkg.rb @@ -6,9 +6,6 @@ require "plist" require "utils/user" require "cask/artifact/abstract_artifact" -require "extend/hash_validator" -using HashValidator - module Cask module Artifact # Artifact corresponding to the `pkg` stanza. diff --git a/Library/Homebrew/cask/artifact/relocated.rb b/Library/Homebrew/cask/artifact/relocated.rb index 3c3aff2950..80d2e727b1 100644 --- a/Library/Homebrew/cask/artifact/relocated.rb +++ b/Library/Homebrew/cask/artifact/relocated.rb @@ -3,9 +3,6 @@ require "cask/artifact/abstract_artifact" -require "extend/hash_validator" -using HashValidator - module Cask module Artifact # Superclass for all artifacts which have a source and a target location. diff --git a/Library/Homebrew/cask/config.rb b/Library/Homebrew/cask/config.rb index f1238a3e10..ad37471258 100644 --- a/Library/Homebrew/cask/config.rb +++ b/Library/Homebrew/cask/config.rb @@ -6,9 +6,6 @@ require "json" require "lazy_object" require "locale" -require "extend/hash_validator" -using HashValidator - module Cask # Configuration for installing casks. # diff --git a/Library/Homebrew/cask/dsl/conflicts_with.rb b/Library/Homebrew/cask/dsl/conflicts_with.rb index 96993ca36b..40b19f6056 100644 --- a/Library/Homebrew/cask/dsl/conflicts_with.rb +++ b/Library/Homebrew/cask/dsl/conflicts_with.rb @@ -3,9 +3,6 @@ require "delegate" -require "extend/hash_validator" -using HashValidator - module Cask class DSL # Class corresponding to the `conflicts_with` stanza. diff --git a/Library/Homebrew/extend/hash_validator.rb b/Library/Homebrew/extend/hash_validator.rb deleted file mode 100644 index 09cfbe68a3..0000000000 --- a/Library/Homebrew/extend/hash_validator.rb +++ /dev/null @@ -1,13 +0,0 @@ -# typed: false -# frozen_string_literal: true - -module HashValidator - refine Hash do - def assert_valid_keys!(*valid_keys) - unknown_keys = keys - valid_keys - return if unknown_keys.empty? - - raise ArgumentError, "invalid keys: #{unknown_keys.map(&:inspect).join(", ")}" - end - end -end diff --git a/Library/Homebrew/extend/hash_validator.rbi b/Library/Homebrew/extend/hash_validator.rbi deleted file mode 100644 index 715b783813..0000000000 --- a/Library/Homebrew/extend/hash_validator.rbi +++ /dev/null @@ -1,6 +0,0 @@ -# typed: strict - -class Hash - sig { params(valid_keys: T.untyped).void } - def assert_valid_keys!(*valid_keys); end -end diff --git a/Library/Homebrew/system_command.rb b/Library/Homebrew/system_command.rb index e069a4e27f..af201706d4 100644 --- a/Library/Homebrew/system_command.rb +++ b/Library/Homebrew/system_command.rb @@ -7,7 +7,6 @@ require "shellwords" require "extend/io" require "extend/predicable" -require "extend/hash_validator" require "extend/time"