Merge pull request #20592 from botantony/typed-strict
keg_only_reason locale: `typed: strict`
This commit is contained in:
commit
53952ecb1e
@ -1,28 +1,34 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Used to annotate formulae that duplicate macOS-provided software
|
# Used to annotate formulae that duplicate macOS-provided software
|
||||||
# or cause conflicts when linked in.
|
# or cause conflicts when linked in.
|
||||||
class KegOnlyReason
|
class KegOnlyReason
|
||||||
|
sig { returns(T.any(Symbol, String)) }
|
||||||
attr_reader :reason
|
attr_reader :reason
|
||||||
|
|
||||||
|
sig { params(reason: T.any(Symbol, String), explanation: String).void }
|
||||||
def initialize(reason, explanation)
|
def initialize(reason, explanation)
|
||||||
@reason = reason
|
@reason = reason
|
||||||
@explanation = explanation
|
@explanation = explanation
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
def versioned_formula?
|
def versioned_formula?
|
||||||
@reason == :versioned_formula
|
@reason == :versioned_formula
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
def provided_by_macos?
|
def provided_by_macos?
|
||||||
@reason == :provided_by_macos
|
@reason == :provided_by_macos
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
def shadowed_by_macos?
|
def shadowed_by_macos?
|
||||||
@reason == :shadowed_by_macos
|
@reason == :shadowed_by_macos
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
def by_macos?
|
def by_macos?
|
||||||
provided_by_macos? || shadowed_by_macos?
|
provided_by_macos? || shadowed_by_macos?
|
||||||
end
|
end
|
||||||
@ -53,10 +59,11 @@ class KegOnlyReason
|
|||||||
parallel can cause all kinds of trouble
|
parallel can cause all kinds of trouble
|
||||||
EOS
|
EOS
|
||||||
else
|
else
|
||||||
@reason
|
@reason.to_s
|
||||||
end.strip
|
end.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Hash[String, String]) }
|
||||||
def to_hash
|
def to_hash
|
||||||
reason_string = if @reason.is_a?(Symbol)
|
reason_string = if @reason.is_a?(Symbol)
|
||||||
@reason.inspect
|
@reason.inspect
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Representation of a system locale.
|
# Representation of a system locale.
|
||||||
@ -24,6 +24,7 @@ class Locale
|
|||||||
LOCALE_REGEX = /\A((?:#{LANGUAGE_REGEX}|#{REGION_REGEX}|#{SCRIPT_REGEX})(?:-|$)){1,3}\Z/
|
LOCALE_REGEX = /\A((?:#{LANGUAGE_REGEX}|#{REGION_REGEX}|#{SCRIPT_REGEX})(?:-|$)){1,3}\Z/
|
||||||
private_constant :LOCALE_REGEX
|
private_constant :LOCALE_REGEX
|
||||||
|
|
||||||
|
sig { params(string: String).returns(T.attached_class) }
|
||||||
def self.parse(string)
|
def self.parse(string)
|
||||||
if (locale = try_parse(string))
|
if (locale = try_parse(string))
|
||||||
return locale
|
return locale
|
||||||
@ -55,25 +56,42 @@ class Locale
|
|||||||
new(language, script, region)
|
new(language, script, region)
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :language, :script, :region
|
sig { returns(T.nilable(String)) }
|
||||||
|
attr_reader :language
|
||||||
|
|
||||||
|
sig { returns(T.nilable(String)) }
|
||||||
|
attr_reader :script
|
||||||
|
|
||||||
|
sig { returns(T.nilable(String)) }
|
||||||
|
attr_reader :region
|
||||||
|
|
||||||
|
sig { params(language: T.nilable(String), script: T.nilable(String), region: T.nilable(String)).void }
|
||||||
def initialize(language, script, region)
|
def initialize(language, script, region)
|
||||||
raise ArgumentError, "#{self.class} cannot be empty" if language.nil? && region.nil? && script.nil?
|
raise ArgumentError, "#{self.class} cannot be empty" if language.nil? && region.nil? && script.nil?
|
||||||
|
|
||||||
{
|
unless language.nil?
|
||||||
language:,
|
regex = LANGUAGE_REGEX
|
||||||
script:,
|
raise ParserError, "'language' does not match #{regex}" unless language.match?(regex)
|
||||||
region:,
|
|
||||||
}.each do |key, value|
|
|
||||||
next if value.nil?
|
|
||||||
|
|
||||||
regex = self.class.const_get(:"#{key.upcase}_REGEX")
|
@language = T.let(language, T.nilable(String))
|
||||||
raise ParserError, "'#{value}' does not match #{regex}" unless value&.match?(regex)
|
|
||||||
|
|
||||||
instance_variable_set(:"@#{key}", value)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless script.nil?
|
||||||
|
regex = SCRIPT_REGEX
|
||||||
|
raise ParserError, "'script' does not match #{regex}" unless script.match?(regex)
|
||||||
|
|
||||||
|
@script = T.let(script, T.nilable(String))
|
||||||
|
end
|
||||||
|
|
||||||
|
return if region.nil?
|
||||||
|
|
||||||
|
regex = REGION_REGEX
|
||||||
|
raise ParserError, "'region' does not match #{regex}" unless region.match?(regex)
|
||||||
|
|
||||||
|
@region = T.let(region, T.nilable(String))
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { params(other: T.any(String, Locale)).returns(T::Boolean) }
|
||||||
def include?(other)
|
def include?(other)
|
||||||
unless other.is_a?(self.class)
|
unless other.is_a?(self.class)
|
||||||
other = self.class.try_parse(other)
|
other = self.class.try_parse(other)
|
||||||
@ -87,6 +105,7 @@ class Locale
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(other: T.any(String, Locale)).returns(T::Boolean) }
|
||||||
def eql?(other)
|
def eql?(other)
|
||||||
unless other.is_a?(self.class)
|
unless other.is_a?(self.class)
|
||||||
other = self.class.try_parse(other)
|
other = self.class.try_parse(other)
|
||||||
@ -99,6 +118,13 @@ class Locale
|
|||||||
end
|
end
|
||||||
alias == eql?
|
alias == eql?
|
||||||
|
|
||||||
|
sig {
|
||||||
|
params(
|
||||||
|
locale_groups: T::Enumerable[T::Enumerable[T.any(String, Locale)]],
|
||||||
|
).returns(
|
||||||
|
T.nilable(T::Enumerable[T.any(String, Locale)]),
|
||||||
|
)
|
||||||
|
}
|
||||||
def detect(locale_groups)
|
def detect(locale_groups)
|
||||||
locale_groups.find { |locales| locales.any? { |locale| eql?(locale) } } ||
|
locale_groups.find { |locales| locales.any? { |locale| eql?(locale) } } ||
|
||||||
locale_groups.find { |locales| locales.any? { |locale| include?(locale) } }
|
locale_groups.find { |locales| locales.any? { |locale| include?(locale) } }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user