Class: Homebrew::Livecheck::Strategy::HeaderMatch Private
- Inherits:
-
Object
- Object
- Homebrew::Livecheck::Strategy::HeaderMatch
- Extended by:
- T::Sig
- Defined in:
- livecheck/strategy/header_match.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
The HeaderMatch strategy follows all URL redirections and scans the resulting headers for matching text using the provided regex.
Constant Summary collapse
- NICE_NAME =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"Header match"
- PRIORITY =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
A priority of zero causes livecheck to skip the strategy. We only apply Homebrew::Livecheck::Strategy::HeaderMatch using
strategy :header_match
in alivecheck
block, as we can’t automatically determine when this can be successfully applied to a URL. 0
- URL_MATCH_REGEX =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
The
Regexp
used to determine if the strategy applies to the URL. %r{^https?://}i.freeze
Class Method Summary collapse
-
.find_versions(url, regex, cask: nil, &block) ⇒ Hash{Symbol => T.untyped}
private
Checks the final URL for new versions after following all redirections, using the provided regex for matching.
-
.match?(url) ⇒ Boolean
private
Whether the strategy can be applied to the provided URL.
Class Method Details
.find_versions(url, regex, cask: nil, &block) ⇒ Hash{Symbol => T.untyped}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Checks the final URL for new versions after following all redirections, using the provided regex for matching.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'livecheck/strategy/header_match.rb', line 47 def self.find_versions(url, regex, cask: nil, &block) match_data = { matches: {}, regex: regex, url: url } headers = Strategy.page_headers(url) # Merge the headers from all responses into one hash merged_headers = headers.reduce(&:merge) if block match = yield merged_headers, regex else match = nil if (filename = merged_headers["content-disposition"]) if regex match ||= filename[regex, 1] else v = Version.parse(filename, detected_from_url: true) match ||= v.to_s unless v.null? end end if (location = merged_headers["location"]) if regex match ||= location[regex, 1] else v = Version.parse(location, detected_from_url: true) match ||= v.to_s unless v.null? end end end match_data[:matches][match] = Version.new(match) if match match_data end |
.match?(url) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
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.
32 33 34 |
# File 'livecheck/strategy/header_match.rb', line 32 def self.match?(url) URL_MATCH_REGEX.match?(url) end |