Remove ActiveSupport Array access core extensions
This commit is contained in:
parent
36024e2a4d
commit
08e12b2383
1
.gitignore
vendored
1
.gitignore
vendored
@ -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
|
||||
|
@ -126,9 +126,9 @@ module Homebrew
|
||||
# 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 = []
|
||||
|
@ -360,7 +360,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy
|
||||
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]
|
||||
|
@ -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.
|
||||
#
|
||||
@ -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
|
||||
|
9
Library/Homebrew/extend/array.rbi
Normal file
9
Library/Homebrew/extend/array.rbi
Normal file
@ -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
|
@ -12,7 +12,6 @@ require "set"
|
||||
|
||||
# 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_PULL_OR_COMMIT_URL_REGEX =
|
||||
HOMEBREW_BOTTLES_EXTNAME_REGEX = /\.([a-z0-9_]+)\.bottle\.(?:(\d+)\.)?tar\.gz$/
|
||||
|
||||
require "extend/module"
|
||||
require "extend/array"
|
||||
require "extend/blank"
|
||||
require "env_config"
|
||||
require "macos_version"
|
||||
@ -130,7 +130,6 @@ module Homebrew
|
||||
end
|
||||
|
||||
require "context"
|
||||
require "extend/array"
|
||||
require "git_repository"
|
||||
require "extend/pathname"
|
||||
require "cli/args"
|
||||
|
@ -92,7 +92,7 @@ class Tab
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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 <tt>Enumerable#excluding</tt> that uses <tt>Array#-</tt>
|
||||
# instead of <tt>Array#reject</tt> for performance reasons.
|
||||
def excluding(*elements)
|
||||
self - elements.flatten(1)
|
||||
end
|
||||
|
||||
# Alias for #excluding.
|
||||
def without(*elements)
|
||||
excluding(*elements)
|
||||
end
|
||||
|
||||
# Equal to <tt>self[1]</tt>.
|
||||
#
|
||||
# %w( a b c d e ).second # => "b"
|
||||
def second
|
||||
self[1]
|
||||
end
|
||||
|
||||
# Equal to <tt>self[2]</tt>.
|
||||
#
|
||||
# %w( a b c d e ).third # => "c"
|
||||
def third
|
||||
self[2]
|
||||
end
|
||||
|
||||
# Equal to <tt>self[3]</tt>.
|
||||
#
|
||||
# %w( a b c d e ).fourth # => "d"
|
||||
def fourth
|
||||
self[3]
|
||||
end
|
||||
|
||||
# Equal to <tt>self[4]</tt>.
|
||||
#
|
||||
# %w( a b c d e ).fifth # => "e"
|
||||
def fifth
|
||||
self[4]
|
||||
end
|
||||
|
||||
# Equal to <tt>self[41]</tt>. Also known as accessing "the reddit".
|
||||
#
|
||||
# (1..42).to_a.forty_two # => 42
|
||||
def forty_two
|
||||
self[41]
|
||||
end
|
||||
|
||||
# Equal to <tt>self[-3]</tt>.
|
||||
#
|
||||
# %w( a b c d e ).third_to_last # => "c"
|
||||
def third_to_last
|
||||
self[-3]
|
||||
end
|
||||
|
||||
# Equal to <tt>self[-2]</tt>.
|
||||
#
|
||||
# %w( a b c d e ).second_to_last # => "d"
|
||||
def second_to_last
|
||||
self[-2]
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user