From 0b67e373ea7b6a34afdfa47194ffb1b883df4890 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Wed, 10 Jan 2024 12:07:04 -0800 Subject: [PATCH] Remove ActiveSupport Array access core extensions --- .gitignore | 1 - Library/Homebrew/cli/parser.rb | 6 +- Library/Homebrew/download_strategy.rb | 2 +- Library/Homebrew/extend/array.rb | 14 ++- Library/Homebrew/extend/array.rbi | 9 ++ Library/Homebrew/global.rb | 3 +- Library/Homebrew/tab.rb | 2 +- Library/Homebrew/utils/gems.rb | 2 +- .../active_support/core_ext/array/access.rb | 104 ------------------ 9 files changed, 29 insertions(+), 114 deletions(-) create mode 100644 Library/Homebrew/extend/array.rbi delete mode 100644 Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/array/access.rb diff --git a/.gitignore b/.gitignore index 459a668d06ee09..7e87d158507c48 100644 --- a/.gitignore +++ b/.gitignore @@ -63,7 +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/array/access.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/enumerable.rb !**/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 diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 4bb9aec91cdb7e..1f2f4cdc186e72 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -126,9 +126,9 @@ def initialize(&block) # Filter out Sorbet runtime type checking method calls. cmd_location = T.must(caller_locations).select do |location| T.must(location.path).exclude?("/gems/sorbet-runtime-") - end.second - @command_name = cmd_location.label.chomp("_args").tr("_", "-") - @is_dev_cmd = cmd_location.absolute_path.start_with?(Commands::HOMEBREW_DEV_CMD_PATH) + end.fetch(1) + @command_name = T.must(cmd_location.label).chomp("_args").tr("_", "-") + @is_dev_cmd = T.must(cmd_location.absolute_path).start_with?(Commands::HOMEBREW_DEV_CMD_PATH) @constraints = [] @conflicts = [] diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 4f9becfad999a6..17ce9fac200681 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -360,7 +360,7 @@ def parse_basename(url, search_query: true) end if search_query && (uri_query = uri.query.presence) - components[:query] = URI.decode_www_form(uri_query).map(&:second) + components[:query] = URI.decode_www_form(uri_query).map { _1.fetch(1) } end else components[:path] = [url] diff --git a/Library/Homebrew/extend/array.rb b/Library/Homebrew/extend/array.rb index 2755ee92bf5a6e..468149e00c9209 100644 --- a/Library/Homebrew/extend/array.rb +++ b/Library/Homebrew/extend/array.rb @@ -1,7 +1,18 @@ -# typed: true +# typed: strict # frozen_string_literal: true class Array + + # Equal to self[1]. + # + # %w( a b c d e ).second # => "b" + def second = self[1] + + # Equal to self[2]. + # + # %w( a b c d e ).third # => "c" + def third = self[2] + # Converts the array to a comma-separated sentence where the last element is # joined by the connector word. # @@ -48,6 +59,7 @@ class Array # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + sig { params(words_connector: String, two_words_connector: String, last_word_connector: String).returns(String) } def to_sentence(words_connector: ", ", two_words_connector: " and ", last_word_connector: " and ") case length when 0 diff --git a/Library/Homebrew/extend/array.rbi b/Library/Homebrew/extend/array.rbi new file mode 100644 index 00000000000000..5255357eadbdab --- /dev/null +++ b/Library/Homebrew/extend/array.rbi @@ -0,0 +1,9 @@ +# typed: strict + +class Array + sig { returns(T.nilable(Elem)) } + def second; end + + sig { returns(T.nilable(Elem)) } + def third; end +end diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 691f5a3f983b4c..8d53a4c928c17e 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -12,7 +12,6 @@ # Only require "core_ext" here to ensure we're only requiring the minimum of # what we need. -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" @@ -71,6 +70,7 @@ HOMEBREW_BOTTLES_EXTNAME_REGEX = /\.([a-z0-9_]+)\.bottle\.(?:(\d+)\.)?tar\.gz$/.freeze require "extend/module" +require "extend/array" require "extend/blank" require "env_config" require "macos_version" @@ -130,7 +130,6 @@ def auto_update_command? end require "context" -require "extend/array" require "git_repository" require "extend/pathname" require "cli/args" diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index d38503bde7da59..25033917e5bdf2 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -92,7 +92,7 @@ def self.from_file_content(content, path) end if attributes["source"]["spec"].nil? - version = PkgVersion.parse path.to_s.split("/").second_to_last + version = PkgVersion.parse path.to_s.split("/")[-2] attributes["source"]["spec"] = if version.head? "head" else diff --git a/Library/Homebrew/utils/gems.rb b/Library/Homebrew/utils/gems.rb index c6762c49856519..54c9786e047484 100644 --- a/Library/Homebrew/utils/gems.rb +++ b/Library/Homebrew/utils/gems.rb @@ -14,7 +14,7 @@ module Homebrew # Bump this whenever a committed vendored gem is later added to gitignore. # This will trigger it to reinstall properly if `brew install-bundler-gems` needs it. - VENDOR_VERSION = 4 + VENDOR_VERSION = 5 private_constant :VENDOR_VERSION RUBY_BUNDLE_VENDOR_DIRECTORY = (HOMEBREW_LIBRARY_PATH/"vendor/bundle/ruby").freeze diff --git a/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/array/access.rb b/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/array/access.rb deleted file mode 100644 index ea01e5891c3970..00000000000000 --- a/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/array/access.rb +++ /dev/null @@ -1,104 +0,0 @@ -# frozen_string_literal: true - -class Array - # Returns the tail of the array from +position+. - # - # %w( a b c d ).from(0) # => ["a", "b", "c", "d"] - # %w( a b c d ).from(2) # => ["c", "d"] - # %w( a b c d ).from(10) # => [] - # %w().from(0) # => [] - # %w( a b c d ).from(-2) # => ["c", "d"] - # %w( a b c ).from(-10) # => [] - def from(position) - self[position, length] || [] - end - - # Returns the beginning of the array up to +position+. - # - # %w( a b c d ).to(0) # => ["a"] - # %w( a b c d ).to(2) # => ["a", "b", "c"] - # %w( a b c d ).to(10) # => ["a", "b", "c", "d"] - # %w().to(0) # => [] - # %w( a b c d ).to(-2) # => ["a", "b", "c"] - # %w( a b c ).to(-10) # => [] - def to(position) - if position >= 0 - take position + 1 - else - self[0..position] - end - end - - # Returns a new array that includes the passed elements. - # - # [ 1, 2, 3 ].including(4, 5) # => [ 1, 2, 3, 4, 5 ] - # [ [ 0, 1 ] ].including([ [ 1, 0 ] ]) # => [ [ 0, 1 ], [ 1, 0 ] ] - def including(*elements) - self + elements.flatten(1) - end - - # Returns a copy of the Array excluding the specified elements. - # - # ["David", "Rafael", "Aaron", "Todd"].excluding("Aaron", "Todd") # => ["David", "Rafael"] - # [ [ 0, 1 ], [ 1, 0 ] ].excluding([ [ 1, 0 ] ]) # => [ [ 0, 1 ] ] - # - # Note: This is an optimization of Enumerable#excluding that uses Array#- - # instead of Array#reject for performance reasons. - def excluding(*elements) - self - elements.flatten(1) - end - - # Alias for #excluding. - def without(*elements) - excluding(*elements) - end - - # Equal to self[1]. - # - # %w( a b c d e ).second # => "b" - def second - self[1] - end - - # Equal to self[2]. - # - # %w( a b c d e ).third # => "c" - def third - self[2] - end - - # Equal to self[3]. - # - # %w( a b c d e ).fourth # => "d" - def fourth - self[3] - end - - # Equal to self[4]. - # - # %w( a b c d e ).fifth # => "e" - def fifth - self[4] - end - - # Equal to self[41]. Also known as accessing "the reddit". - # - # (1..42).to_a.forty_two # => 42 - def forty_two - self[41] - end - - # Equal to self[-3]. - # - # %w( a b c d e ).third_to_last # => "c" - def third_to_last - self[-3] - end - - # Equal to self[-2]. - # - # %w( a b c d e ).second_to_last # => "d" - def second_to_last - self[-2] - end -end