Merge pull request #15018 from dduugg/rm-hash-refinement

Use ActiveSupport Hash#assert_valid_keys instead of refinement
This commit is contained in:
Mike McQuaid 2023-03-20 13:48:47 +00:00 committed by GitHub
commit 1e4abe2cc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 7 additions and 47 deletions

View File

@ -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
@ -38,7 +36,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

View File

@ -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.

View File

@ -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.
@ -67,7 +64,7 @@ module Cask
)
end
args.assert_valid_keys!(*VALID_KEYS)
args.assert_valid_keys(*VALID_KEYS)
new(cask, **args)
end

View File

@ -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.
@ -18,7 +15,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

View File

@ -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.
@ -20,7 +17,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 ||= {}

View File

@ -6,9 +6,6 @@ require "json"
require "lazy_object"
require "locale"
require "extend/hash_validator"
using HashValidator
module Cask
# Configuration for installing casks.
#
@ -110,8 +107,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])]) }

View File

@ -3,9 +3,6 @@
require "delegate"
require "extend/hash_validator"
using HashValidator
module Cask
class DSL
# Class corresponding to the `conflicts_with` stanza.
@ -22,7 +19,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

View File

@ -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

View File

@ -1,6 +0,0 @@
# typed: strict
class Hash
sig { params(valid_keys: T.untyped).void }
def assert_valid_keys!(*valid_keys); end
end

View File

@ -7,7 +7,6 @@ require "shellwords"
require "extend/io"
require "extend/predicable"
require "extend/hash_validator"
require "extend/time"