mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Move nil check inside demodulize
This commit is contained in:
parent
f6d0146b1a
commit
936b9b5369
@ -31,7 +31,7 @@ module Homebrew
|
||||
sig { params(strategy_class: T::Class[T.anything]).returns(String) }
|
||||
private_class_method def self.livecheck_strategy_names(strategy_class)
|
||||
@livecheck_strategy_names ||= T.let({}, T.nilable(T::Hash[T::Class[T.anything], String]))
|
||||
@livecheck_strategy_names[strategy_class] ||= Utils.demodulize(T.must(strategy_class.name))
|
||||
@livecheck_strategy_names[strategy_class] ||= Utils.demodulize(strategy_class.name)
|
||||
end
|
||||
|
||||
# Uses `formulae_and_casks_to_check` to identify taps in use other than
|
||||
|
@ -47,7 +47,7 @@ module Homebrew
|
||||
def self.find_versions(url:, regex: nil, provided_content: nil, **unused, &block)
|
||||
if regex.present? && block.blank?
|
||||
raise ArgumentError,
|
||||
"#{Utils.demodulize(T.must(name))} only supports a regex when using a `strategy` block"
|
||||
"#{Utils.demodulize(name)} only supports a regex when using a `strategy` block"
|
||||
end
|
||||
|
||||
Yaml.find_versions(
|
||||
|
@ -92,11 +92,9 @@ module Homebrew
|
||||
def self.find_versions(cask:, url: nil, regex: nil, **_unused, &block)
|
||||
if regex.present? && block.blank?
|
||||
raise ArgumentError,
|
||||
"#{Utils.demodulize(T.must(name))} only supports a regex when using a `strategy` block"
|
||||
end
|
||||
unless T.unsafe(cask)
|
||||
raise ArgumentError, "The #{Utils.demodulize(T.must(name))} strategy only supports casks."
|
||||
"#{Utils.demodulize(name)} only supports a regex when using a `strategy` block"
|
||||
end
|
||||
raise ArgumentError, "The #{Utils.demodulize(name)} strategy only supports casks." unless T.unsafe(cask)
|
||||
|
||||
match_data = { matches: {}, regex:, url: }
|
||||
|
||||
|
@ -107,7 +107,7 @@ module Homebrew
|
||||
).returns(T::Hash[Symbol, T.untyped])
|
||||
}
|
||||
def self.find_versions(url:, regex: nil, provided_content: nil, homebrew_curl: false, **unused, &block)
|
||||
raise ArgumentError, "#{Utils.demodulize(T.must(name))} requires a `strategy` block" if block.blank?
|
||||
raise ArgumentError, "#{Utils.demodulize(name)} requires a `strategy` block" if block.blank?
|
||||
|
||||
match_data = { matches: {}, regex:, url: }
|
||||
return match_data if url.blank? || block.blank?
|
||||
|
@ -91,7 +91,7 @@ module Homebrew
|
||||
}
|
||||
def self.find_versions(url:, regex: nil, provided_content: nil, homebrew_curl: false, **unused, &block)
|
||||
if regex.blank? && block.blank?
|
||||
raise ArgumentError, "#{Utils.demodulize(T.must(name))} requires a regex or `strategy` block"
|
||||
raise ArgumentError, "#{Utils.demodulize(name)} requires a regex or `strategy` block"
|
||||
end
|
||||
|
||||
match_data = { matches: {}, regex:, url: }
|
||||
|
@ -228,7 +228,7 @@ module Homebrew
|
||||
def self.find_versions(url:, regex: nil, homebrew_curl: false, **unused, &block)
|
||||
if regex.present? && block.blank?
|
||||
raise ArgumentError,
|
||||
"#{Utils.demodulize(T.must(name))} only supports a regex when using a `strategy` block"
|
||||
"#{Utils.demodulize(name)} only supports a regex when using a `strategy` block"
|
||||
end
|
||||
|
||||
match_data = { matches: {}, regex:, url: }
|
||||
|
@ -147,7 +147,7 @@ module Homebrew
|
||||
).returns(T::Hash[Symbol, T.untyped])
|
||||
}
|
||||
def self.find_versions(url:, regex: nil, provided_content: nil, homebrew_curl: false, **unused, &block)
|
||||
raise ArgumentError, "#{Utils.demodulize(T.must(name))} requires a `strategy` block" if block.blank?
|
||||
raise ArgumentError, "#{Utils.demodulize(name)} requires a `strategy` block" if block.blank?
|
||||
|
||||
match_data = { matches: {}, regex:, url: }
|
||||
return match_data if url.blank? || block.blank?
|
||||
|
@ -107,7 +107,7 @@ module Homebrew
|
||||
).returns(T::Hash[Symbol, T.untyped])
|
||||
}
|
||||
def self.find_versions(url:, regex: nil, provided_content: nil, homebrew_curl: false, **unused, &block)
|
||||
raise ArgumentError, "#{Utils.demodulize(T.must(name))} requires a `strategy` block" if block.blank?
|
||||
raise ArgumentError, "#{Utils.demodulize(name)} requires a `strategy` block" if block.blank?
|
||||
|
||||
match_data = { matches: {}, regex:, url: }
|
||||
return match_data if url.blank? || block.blank?
|
||||
|
@ -30,6 +30,10 @@ RSpec.describe Utils do
|
||||
expect(described_class.demodulize("")).to eq("")
|
||||
expect(described_class.demodulize("::")).to eq("")
|
||||
end
|
||||
|
||||
it "raise an ArgumentError when passed nil" do
|
||||
expect { described_class.demodulize(nil) }.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
specify ".parse_author!" do
|
||||
|
@ -97,8 +97,11 @@ module Utils
|
||||
# See also #deconstantize.
|
||||
# @see https://github.com/rails/rails/blob/b0dd7c7/activesupport/lib/active_support/inflector/methods.rb#L230-L245
|
||||
# `ActiveSupport::Inflector.demodulize`
|
||||
sig { params(path: String).returns(String) }
|
||||
# @raise [ArgumentError] if the provided path is nil
|
||||
sig { params(path: T.nilable(String)).returns(String) }
|
||||
def self.demodulize(path)
|
||||
raise ArgumentError, "No constant path provided" if path.nil?
|
||||
|
||||
if (i = path.rindex("::"))
|
||||
T.must(path[(i + 2)..])
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user