PageMatch: Enforce requirements in #find_versions

This aligns `PageMatch` with how cask strategies handle requirements
in their `#find_versions` methods. This moves related logic from
`Livecheck#latest_version` into the `PageMatch` strategy, which feels
a bit more appropriate.
This commit is contained in:
Sam Ford 2021-11-19 23:37:29 -05:00
parent 085827f605
commit f8ded0a435
No known key found for this signature in database
GPG Key ID: 95209E46C7FFDEFE
2 changed files with 6 additions and 5 deletions

View File

@ -626,13 +626,10 @@ module Homebrew
end
if livecheck_strategy.present?
if livecheck_strategy == :page_match && (livecheck_regex.blank? && livecheck_strategy_block.blank?)
odebug "#{strategy_name} strategy requires a regex or block"
next
elsif livecheck_url.blank?
if livecheck_url.blank?
odebug "#{strategy_name} strategy requires a URL"
next
elsif strategies.exclude?(strategy)
elsif livecheck_strategy != :page_match && strategies.exclude?(strategy)
odebug "#{strategy_name} strategy does not apply to this URL"
next
end

View File

@ -90,6 +90,10 @@ module Homebrew
).returns(T::Hash[Symbol, T.untyped])
}
def self.find_versions(url:, regex: nil, provided_content: nil, **_unused, &block)
if regex.blank? && block.blank?
raise ArgumentError, "#{T.must(name).demodulize} requires a regex or `strategy` block"
end
match_data = { matches: {}, regex: regex, url: url }
return match_data if url.blank? || (regex.blank? && block.blank?)