Replace demodulize inflection with util
This commit is contained in:
parent
37015b6b08
commit
d62211d3af
@ -55,7 +55,7 @@ module Formulary
|
||||
namespace = klass.name.deconstantize
|
||||
next if namespace.deconstantize != name
|
||||
|
||||
remove_const(namespace.demodulize)
|
||||
remove_const(Utils::Inflection.demodulize(namespace))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ module Homebrew
|
||||
constant = Strategy.const_get(const_symbol)
|
||||
next unless constant.is_a?(Class)
|
||||
|
||||
@livecheck_strategy_names[constant] = T.must(constant.name).demodulize
|
||||
@livecheck_strategy_names[constant] = Utils::Inflection.demodulize(T.must(constant.name))
|
||||
end
|
||||
@livecheck_strategy_names.freeze
|
||||
end
|
||||
|
||||
@ -73,7 +73,7 @@ module Homebrew
|
||||
}
|
||||
def self.find_versions(url:, regex: nil, **_unused, &block)
|
||||
if regex.present? && block.blank?
|
||||
raise ArgumentError, "#{T.must(name).demodulize} only supports a regex when using a `strategy` block"
|
||||
raise ArgumentError, "#{Utils::Inflection.demodulize(T.must(name))} only supports a regex when using a `strategy` block"
|
||||
end
|
||||
|
||||
match_data = { matches: {}, regex: regex, url: url }
|
||||
|
||||
@ -97,9 +97,9 @@ module Homebrew
|
||||
}
|
||||
def self.find_versions(cask:, url: nil, regex: nil, **_unused, &block)
|
||||
if regex.present? && block.blank?
|
||||
raise ArgumentError, "#{T.must(name).demodulize} only supports a regex when using a `strategy` block"
|
||||
raise ArgumentError, "#{Utils::Inflection.demodulize(T.must(name))} only supports a regex when using a `strategy` block"
|
||||
end
|
||||
raise ArgumentError, "The #{T.must(name).demodulize} strategy only supports casks." unless T.unsafe(cask)
|
||||
raise ArgumentError, "The #{Utils::Inflection.demodulize(T.must(name))} strategy only supports casks." unless T.unsafe(cask)
|
||||
|
||||
match_data = { matches: {}, regex: regex, url: url }
|
||||
|
||||
|
||||
@ -93,7 +93,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, "#{T.must(name).demodulize} requires a regex or `strategy` block"
|
||||
raise ArgumentError, "#{Utils::Inflection.demodulize(T.must(name))} requires a regex or `strategy` block"
|
||||
end
|
||||
|
||||
match_data = { matches: {}, regex: regex, url: url }
|
||||
|
||||
@ -203,7 +203,7 @@ module Homebrew
|
||||
}
|
||||
def self.find_versions(url:, regex: nil, **_unused, &block)
|
||||
if regex.present? && block.blank?
|
||||
raise ArgumentError, "#{T.must(name).demodulize} only supports a regex when using a `strategy` block"
|
||||
raise ArgumentError, "#{Utils::Inflection.demodulize(T.must(name))} only supports a regex when using a `strategy` block"
|
||||
end
|
||||
|
||||
match_data = { matches: {}, regex: regex, url: url }
|
||||
|
||||
@ -7,6 +7,24 @@ module Utils
|
||||
# @api private
|
||||
module Inflection
|
||||
extend T::Sig
|
||||
# Removes the module part from the expression in the string.
|
||||
#
|
||||
# demodulize('ActiveSupport::Inflector::Inflections') # => "Inflections"
|
||||
# demodulize('Inflections') # => "Inflections"
|
||||
# demodulize('::Inflections') # => "Inflections"
|
||||
# demodulize('') # => ""
|
||||
#
|
||||
# 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) }
|
||||
def self.demodulize(path)
|
||||
if (i = path.rindex("::"))
|
||||
T.must(path[(i + 2)..])
|
||||
else
|
||||
path
|
||||
end
|
||||
end
|
||||
|
||||
# Combines `stem` with the `singular` or `plural` suffix based on `count`.
|
||||
sig { params(stem: String, count: Integer, plural: String, singular: String).returns(String) }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user