From f8ded0a435700d1969a779d7b75047fbd2176d7a Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Fri, 19 Nov 2021 23:37:29 -0500 Subject: [PATCH] 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. --- Library/Homebrew/livecheck/livecheck.rb | 7 ++----- Library/Homebrew/livecheck/strategy/page_match.rb | 4 ++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index b2b1f03570..bccbf45c51 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -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 diff --git a/Library/Homebrew/livecheck/strategy/page_match.rb b/Library/Homebrew/livecheck/strategy/page_match.rb index d4f57d6b0a..7ef3735636 100644 --- a/Library/Homebrew/livecheck/strategy/page_match.rb +++ b/Library/Homebrew/livecheck/strategy/page_match.rb @@ -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?)