From 3933b866b697e3b488988536fa71984c3b392861 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Sat, 19 Dec 2020 11:36:16 -0500 Subject: [PATCH] Sparkle: Align with PageMatch This inlines the `PRIORITY` and `#match?` logic from `PageMatch` into `Sparkle` instead of subclassing `PageMatch`. `Sparkle` doesn't really make sense as a subclass of `PageMatch` (since it functions in a completely different manner), so it's better to simply copy over these parts of `PageMatch`. This also helps to separate the strategies, so any changes to `PRIORITY` or `#match?` in `PageMatch` won't affect `Sparkle`. --- .../Homebrew/livecheck/strategy/sparkle.rb | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/livecheck/strategy/sparkle.rb b/Library/Homebrew/livecheck/strategy/sparkle.rb index 3e202ceb9f..c90649ceef 100644 --- a/Library/Homebrew/livecheck/strategy/sparkle.rb +++ b/Library/Homebrew/livecheck/strategy/sparkle.rb @@ -11,9 +11,27 @@ module Homebrew # its contents as a Sparkle appcast in XML format. # # @api private - class Sparkle < PageMatch + class Sparkle extend T::Sig + # A priority of zero causes livecheck to skip the strategy. We only + # apply {Sparkle} using `strategy :sparkle` in a `livecheck` block, + # as we can't automatically determine when this can be successfully + # applied to a URL without fetching the content. + PRIORITY = 0 + + # The `Regexp` used to determine if the strategy applies to the URL. + URL_MATCH_REGEX = %r{^https?://}i.freeze + + # Whether the strategy can be applied to the provided URL. + # The strategy will technically match any HTTP URL but is + # only usable with a `livecheck` block containing a regex + # or block. + sig { params(url: String).returns(T::Boolean) } + def self.match?(url) + URL_MATCH_REGEX.match?(url) + end + Item = Struct.new(:title, :url, :bundle_version, :short_version, :version, keyword_init: true) do extend T::Sig