Class: Homebrew::Livecheck::Strategy::Hackage
- Defined in:
- livecheck/strategy/hackage.rb
Overview
The Hackage strategy identifies versions of software at hackage.haskell.org by checking directory listing pages.
Hackage URLs take one of the following formats:
https://hackage.haskell.org/package/example-1.2.3/example-1.2.3.tar.gz
https://downloads.haskell.org/~ghc/8.10.1/ghc-8.10.1-src.tar.xz
The default regex checks for the latest version in an h3
heading element
with a format like <h3>example-1.2.3/</h3>
.
Constant Summary collapse
- PACKAGE_NAME_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.
A
Regexp
used in determining if the strategy applies to the URL and also as part of extracting the package name from the URL basename. /(?<package_name>.+?)-\d+/i
- FILENAME_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.
A
Regexp
used to extract the package name from the URL basename. /^#{PACKAGE_NAME_REGEX.source.strip}/i
- 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.
A
Regexp
used in determining if the strategy applies to the URL. %r{ ^https?://(?:downloads|hackage)\.haskell\.org (?:/[^/]+)+ # Path before the filename #{PACKAGE_NAME_REGEX.source.strip} }ix
Class Method Summary collapse
-
.find_versions(url:, regex: nil, **unused, &block) ⇒ Hash{Symbol => T.untyped}
private
Generates a URL and regex (if one isn't provided) and passes them to PageMatch.find_versions to identify versions in the content.
-
.generate_input_values(url) ⇒ Hash{Symbol => T.untyped}
private
Extracts information from a provided URL and uses it to generate various input values used by the strategy to check for new versions.
-
.match?(url) ⇒ Boolean
private
Whether the strategy can be applied to the provided URL.
Class Method Details
.find_versions(url:, regex: nil, **unused, &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.
Generates a URL and regex (if one isn't provided) and passes them to PageMatch.find_versions to identify versions in the content.
82 83 84 85 86 |
# File 'livecheck/strategy/hackage.rb', line 82 def self.find_versions(url:, regex: nil, **unused, &block) generated = generate_input_values(url) PageMatch.find_versions(url: generated[:url], regex: regex || generated[:regex], **unused, &block) end |
.generate_input_values(url) ⇒ 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.
Extracts information from a provided URL and uses it to generate
various input values used by the strategy to check for new versions.
Some of these values act as defaults and can be overridden in a
livecheck
block.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'livecheck/strategy/hackage.rb', line 51 def self.generate_input_values(url) values = {} match = File.basename(url).match(FILENAME_REGEX) return values if match.blank? # A page containing a directory listing of the latest source tarball values[:url] = "https://hackage.haskell.org/package/#{match[:package_name]}/src/" regex_name = Regexp.escape(T.must(match[:package_name])).gsub("\\-", "-") # Example regex: `%r{<h3>example-(.*?)/?</h3>}i` values[:regex] = %r{<h3>#{regex_name}-(.*?)/?</h3>}i values 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.
39 40 41 |
# File 'livecheck/strategy/hackage.rb', line 39 def self.match?(url) URL_MATCH_REGEX.match?(url) end |