Merge pull request #16320 from dduugg/use-native-except
Use native Hash#except, remove ActiveSupport 🐵-patch
This commit is contained in:
commit
7755004325
2
.gitignore
vendored
2
.gitignore
vendored
@ -68,9 +68,7 @@
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/file/atomic.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/deep_merge.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/deep_transform_values.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/except.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/keys.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/slice.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/deep_dup.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/duplicable.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/exclude.rb
|
||||
|
||||
@ -5,8 +5,6 @@ require "cli/parser"
|
||||
require "utils/github"
|
||||
require "manpages"
|
||||
|
||||
require "active_support/core_ext/hash/slice"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
@ -39,7 +37,7 @@ module Homebrew
|
||||
|
||||
sentences = {}
|
||||
members.each do |group, hash|
|
||||
hash.slice!(*public_members)
|
||||
hash.replace(hash.slice(*public_members))
|
||||
hash.each { |login, name| hash[login] = "[#{name}](https://github.com/#{login})" }
|
||||
sentences[group] = hash.values.sort.to_sentence
|
||||
end
|
||||
|
||||
@ -16,7 +16,6 @@ require "active_support/core_ext/array/access"
|
||||
require "active_support/core_ext/enumerable"
|
||||
require "active_support/core_ext/file/atomic"
|
||||
require "active_support/core_ext/hash/deep_merge"
|
||||
require "active_support/core_ext/hash/except"
|
||||
require "active_support/core_ext/hash/keys"
|
||||
require "active_support/core_ext/string/exclude"
|
||||
require "active_support/core_ext/string/filters"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "livecheck/constants"
|
||||
@ -18,18 +18,18 @@ module Homebrew
|
||||
module Livecheck
|
||||
module_function
|
||||
|
||||
GITEA_INSTANCES = %w[
|
||||
GITEA_INSTANCES = T.let(%w[
|
||||
codeberg.org
|
||||
gitea.com
|
||||
opendev.org
|
||||
tildegit.org
|
||||
].freeze
|
||||
].freeze, T::Array[String])
|
||||
|
||||
GOGS_INSTANCES = %w[
|
||||
GOGS_INSTANCES = T.let(%w[
|
||||
lolg.it
|
||||
].freeze
|
||||
].freeze, T::Array[String])
|
||||
|
||||
STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL = [
|
||||
STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL = T.let([
|
||||
:extract_plist,
|
||||
:github_latest,
|
||||
:header_match,
|
||||
@ -38,9 +38,9 @@ module Homebrew
|
||||
:sparkle,
|
||||
:xml,
|
||||
:yaml,
|
||||
].freeze
|
||||
].freeze, T::Array[Symbol])
|
||||
|
||||
UNSTABLE_VERSION_KEYWORDS = %w[
|
||||
UNSTABLE_VERSION_KEYWORDS = T.let(%w[
|
||||
alpha
|
||||
beta
|
||||
bpo
|
||||
@ -49,21 +49,21 @@ module Homebrew
|
||||
prerelease
|
||||
preview
|
||||
rc
|
||||
].freeze
|
||||
].freeze, T::Array[String])
|
||||
|
||||
sig { returns(T::Hash[Class, String]) }
|
||||
def livecheck_strategy_names
|
||||
return @livecheck_strategy_names if defined?(@livecheck_strategy_names)
|
||||
return T.must(@livecheck_strategy_names) if defined?(@livecheck_strategy_names)
|
||||
|
||||
# Cache demodulized strategy names, to avoid repeating this work
|
||||
@livecheck_strategy_names = {}
|
||||
@livecheck_strategy_names = T.let({}, T.nilable(T::Hash[Class, String]))
|
||||
Strategy.constants.sort.each do |const_symbol|
|
||||
constant = Strategy.const_get(const_symbol)
|
||||
next unless constant.is_a?(Class)
|
||||
|
||||
@livecheck_strategy_names[constant] = Utils.demodulize(T.must(constant.name))
|
||||
T.must(@livecheck_strategy_names)[constant] = Utils.demodulize(T.must(constant.name))
|
||||
end
|
||||
@livecheck_strategy_names.freeze
|
||||
T.must(@livecheck_strategy_names).freeze
|
||||
end
|
||||
|
||||
# Uses `formulae_and_casks_to_check` to identify taps in use other than
|
||||
@ -83,7 +83,7 @@ module Homebrew
|
||||
|
||||
other_taps.each_value do |tap|
|
||||
tap_strategy_path = "#{tap.path}/livecheck/strategy"
|
||||
Dir["#{tap_strategy_path}/*.rb"].sort.each(&method(:require)) if Dir.exist?(tap_strategy_path)
|
||||
Dir["#{tap_strategy_path}/*.rb"].sort.each { require(_1) } if Dir.exist?(tap_strategy_path)
|
||||
end
|
||||
end
|
||||
|
||||
@ -321,7 +321,12 @@ module Homebrew
|
||||
latest_info = status_hash(formula_or_cask, "error", [no_versions_msg], full_name: use_full_name,
|
||||
verbose: verbose)
|
||||
if check_for_resources
|
||||
resource_version_info.map! { |r| r.except!(:meta) } unless verbose
|
||||
unless verbose
|
||||
resource_version_info.map! do |info|
|
||||
info.delete(:meta)
|
||||
info
|
||||
end
|
||||
end
|
||||
latest_info[:resources] = resource_version_info
|
||||
end
|
||||
|
||||
@ -368,8 +373,13 @@ module Homebrew
|
||||
|
||||
if json
|
||||
progress&.increment
|
||||
info.except!(:meta) unless verbose
|
||||
resource_version_info.map! { |r| r.except!(:meta) } if check_for_resources && !verbose
|
||||
info.delete(:meta) unless verbose
|
||||
if check_for_resources && !verbose
|
||||
resource_version_info.map! do |info|
|
||||
info.delete(:meta)
|
||||
info
|
||||
end
|
||||
end
|
||||
next info
|
||||
end
|
||||
puts if debug
|
||||
@ -446,7 +456,7 @@ module Homebrew
|
||||
messages: T.nilable(T::Array[String]),
|
||||
full_name: T::Boolean,
|
||||
verbose: T::Boolean,
|
||||
).returns(Hash)
|
||||
).returns(T::Hash[Symbol, T.untyped])
|
||||
}
|
||||
def status_hash(package_or_resource, status_str, messages = nil, full_name: false, verbose: false)
|
||||
formula = package_or_resource if package_or_resource.is_a?(Formula)
|
||||
@ -473,7 +483,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
# Formats and prints the livecheck result for a formula/cask/resource.
|
||||
sig { params(info: Hash, verbose: T::Boolean, ambiguous_cask: T::Boolean).void }
|
||||
sig { params(info: T::Hash[Symbol, T.untyped], verbose: T::Boolean, ambiguous_cask: T::Boolean).void }
|
||||
def print_latest_version(info, verbose: false, ambiguous_cask: false)
|
||||
package_or_resource_s = info[:resource].present? ? " " : ""
|
||||
package_or_resource_s += "#{Tty.blue}#{info[:formula] || info[:cask] || info[:resource]}#{Tty.reset}"
|
||||
@ -496,7 +506,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
# Prints the livecheck result for the resources of a given Formula.
|
||||
sig { params(info: T::Array[Hash], verbose: T::Boolean).void }
|
||||
sig { params(info: T::Array[T::Hash[Symbol, T.untyped]], verbose: T::Boolean).void }
|
||||
def print_resources_info(info, verbose: false)
|
||||
info.each do |r_info|
|
||||
if r_info[:status] && r_info[:messages]
|
||||
@ -633,7 +643,7 @@ module Homebrew
|
||||
full_name: T::Boolean,
|
||||
verbose: T::Boolean,
|
||||
debug: T::Boolean,
|
||||
).returns(T.nilable(Hash))
|
||||
).returns(T.nilable(T::Hash[Symbol, T.untyped]))
|
||||
}
|
||||
def latest_version(
|
||||
formula_or_cask,
|
||||
@ -834,6 +844,7 @@ module Homebrew
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
# Identifies the latest version of a resource and returns a Hash containing the
|
||||
# version information. Returns nil if a latest version couldn't be found.
|
||||
sig {
|
||||
@ -844,7 +855,7 @@ module Homebrew
|
||||
debug: T::Boolean,
|
||||
quiet: T::Boolean,
|
||||
verbose: T::Boolean,
|
||||
).returns(Hash)
|
||||
).returns(T::Hash[Symbol, T.untyped])
|
||||
}
|
||||
def resource_version(
|
||||
resource,
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Hash
|
||||
# Returns a hash that includes everything except given keys.
|
||||
# hash = { a: true, b: false, c: nil }
|
||||
# hash.except(:c) # => { a: true, b: false }
|
||||
# hash.except(:a, :b) # => { c: nil }
|
||||
# hash # => { a: true, b: false, c: nil }
|
||||
#
|
||||
# This is useful for limiting a set of parameters to everything but a few known toggles:
|
||||
# @person.update(params[:person].except(:admin))
|
||||
def except(*keys)
|
||||
slice(*self.keys - keys)
|
||||
end unless method_defined?(:except)
|
||||
|
||||
# Removes the given keys from hash and returns it.
|
||||
# hash = { a: true, b: false, c: nil }
|
||||
# hash.except!(:c) # => { a: true, b: false }
|
||||
# hash # => { a: true, b: false }
|
||||
def except!(*keys)
|
||||
keys.each { |key| delete(key) }
|
||||
self
|
||||
end
|
||||
end
|
||||
@ -1,27 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Hash
|
||||
# Replaces the hash with only the given keys.
|
||||
# Returns a hash containing the removed key/value pairs.
|
||||
#
|
||||
# hash = { a: 1, b: 2, c: 3, d: 4 }
|
||||
# hash.slice!(:a, :b) # => {:c=>3, :d=>4}
|
||||
# hash # => {:a=>1, :b=>2}
|
||||
def slice!(*keys)
|
||||
omit = slice(*self.keys - keys)
|
||||
hash = slice(*keys)
|
||||
hash.default = default
|
||||
hash.default_proc = default_proc if default_proc
|
||||
replace(hash)
|
||||
omit
|
||||
end
|
||||
|
||||
# Removes and returns the key/value pairs matching the given keys.
|
||||
#
|
||||
# hash = { a: 1, b: 2, c: 3, d: 4 }
|
||||
# hash.extract!(:a, :b) # => {:a=>1, :b=>2}
|
||||
# hash # => {:c=>3, :d=>4}
|
||||
def extract!(*keys)
|
||||
keys.each_with_object(self.class.new) { |key, result| result[key] = delete(key) if has_key?(key) }
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user