mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Add Hash#deep_merge to extend/
This commit is contained in:
parent
8e9d294df2
commit
0cdd4eee3b
2
.gitignore
vendored
2
.gitignore
vendored
@ -63,8 +63,6 @@
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/*/
|
||||
!**/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/keys.rb
|
||||
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/deep_dup.rb
|
||||
|
@ -11,6 +11,7 @@ require "utils/inreplace"
|
||||
require "erb"
|
||||
require "utils/gzip"
|
||||
require "api"
|
||||
require "extend/hash/deep_merge"
|
||||
|
||||
BOTTLE_ERB = <<-EOS.freeze
|
||||
bottle do
|
||||
|
@ -5,6 +5,7 @@ require "cli/parser"
|
||||
require "formula"
|
||||
require "github_packages"
|
||||
require "github_releases"
|
||||
require "extend/hash/deep_merge"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
@ -17,6 +17,11 @@ class Array
|
||||
# %w( a b c d e ).fourth # => "d"
|
||||
def fourth = self[3]
|
||||
|
||||
# Equal to <tt>self[4]</tt>.
|
||||
#
|
||||
# %w( a b c d e ).fifth # => "e"
|
||||
def fifth = self[4]
|
||||
|
||||
# Converts the array to a comma-separated sentence where the last element is
|
||||
# joined by the connector word.
|
||||
#
|
||||
|
@ -9,4 +9,7 @@ class Array
|
||||
|
||||
sig { returns(T.nilable(Elem)) }
|
||||
def fourth; end
|
||||
|
||||
sig { returns(T.nilable(Elem)) }
|
||||
def fifth; end
|
||||
end
|
||||
|
@ -1,3 +1,4 @@
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Hash
|
||||
@ -22,10 +23,10 @@ class Hash
|
||||
# Same as +deep_merge+, but modifies +self+.
|
||||
def deep_merge!(other_hash, &block)
|
||||
merge!(other_hash) do |key, this_val, other_val|
|
||||
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
||||
this_val.deep_merge(other_val, &block)
|
||||
elsif block_given?
|
||||
block.call(key, this_val, other_val)
|
||||
if T.unsafe(this_val).is_a?(Hash) && other_val.is_a?(Hash)
|
||||
T.unsafe(this_val).deep_merge(other_val, &block)
|
||||
elsif block
|
||||
yield(key, this_val, other_val)
|
||||
else
|
||||
other_val
|
||||
end
|
20
Library/Homebrew/extend/hash/deep_merge.rbi
Normal file
20
Library/Homebrew/extend/hash/deep_merge.rbi
Normal file
@ -0,0 +1,20 @@
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Hash
|
||||
sig do
|
||||
type_parameters(:k2).params(
|
||||
other_hash: T::Hash[T.type_parameter(:k2), T.untyped],
|
||||
block: T.nilable(T.proc.params(k: T.untyped, v1: T.untyped, v2: T.untyped).returns(T.untyped))
|
||||
).returns(T::Hash[T.any(Hash::K, T.type_parameter(:k2)), T.untyped])
|
||||
end
|
||||
def deep_merge(other_hash, &block); end
|
||||
|
||||
sig do
|
||||
type_parameters(:k2).params(
|
||||
other_hash: T::Hash[T.type_parameter(:k2), T.untyped],
|
||||
block: T.nilable(T.proc.params(k: T.untyped, v1: T.untyped, v2: T.untyped).returns(T.untyped))
|
||||
).returns(T::Hash[T.any(Hash::K, T.type_parameter(:k2)), T.untyped])
|
||||
end
|
||||
def deep_merge!(other_hash, &block); end
|
||||
end
|
@ -10,7 +10,6 @@ require "json/add/exception"
|
||||
require "forwardable"
|
||||
require "set"
|
||||
|
||||
require "active_support/core_ext/hash/deep_merge"
|
||||
require "active_support/core_ext/hash/keys"
|
||||
|
||||
HOMEBREW_API_DEFAULT_DOMAIN = ENV.fetch("HOMEBREW_API_DEFAULT_DOMAIN").freeze
|
||||
|
@ -17,7 +17,7 @@ describe "RuboCop" do
|
||||
end
|
||||
|
||||
it "loads all Formula cops without errors" do
|
||||
stdout, stderr, status = Open3.capture3(RUBY_PATH, "-W0", "-S", "rubocop", TEST_FIXTURE_DIR/"testball.rb")
|
||||
stdout, stderr, status = Open3.capture3(RUBY_PATH, "-W0", "-S", "rubocop", "-d", TEST_FIXTURE_DIR/"testball.rb")
|
||||
expect(stderr).to be_empty
|
||||
expect(stdout).to include("no offenses detected")
|
||||
expect(status).to be_a_success
|
||||
|
Loading…
x
Reference in New Issue
Block a user