Skip to content

Commit

Permalink
Remove ActiveSupport Array access core extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Jan 10, 2024
1 parent 11e4b66 commit 0b67e37
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 114 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/cli/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 13 additions & 1 deletion Library/Homebrew/extend/array.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# typed: true
# typed: strict
# frozen_string_literal: true

class Array

# Equal to <tt>self[1]</tt>.
#
# %w( a b c d e ).second # => "b"
def second = self[1]

# Equal to <tt>self[2]</tt>.
#
# %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.
#
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions Library/Homebrew/extend/array.rbi
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions Library/Homebrew/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -130,7 +130,6 @@ def auto_update_command?
end

require "context"
require "extend/array"
require "git_repository"
require "extend/pathname"
require "cli/args"
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/utils/gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

0 comments on commit 0b67e37

Please sign in to comment.