mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #15018 from dduugg/rm-hash-refinement
Use ActiveSupport Hash#assert_valid_keys instead of refinement
This commit is contained in:
commit
1e4abe2cc9
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 ||= {}
|
||||
|
@ -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])]) }
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -1,6 +0,0 @@
|
||||
# typed: strict
|
||||
|
||||
class Hash
|
||||
sig { params(valid_keys: T.untyped).void }
|
||||
def assert_valid_keys!(*valid_keys); end
|
||||
end
|
@ -7,7 +7,6 @@ require "shellwords"
|
||||
|
||||
require "extend/io"
|
||||
require "extend/predicable"
|
||||
require "extend/hash_validator"
|
||||
|
||||
require "extend/time"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user