If the upstream version format does not match the required formula/cask format, use a strategy block to transform the data. The arguments passed to the block depend on the strategy used.
PageMatch strategy
Used for scanning HTML content. The block receives |page, regex|.
- Default: Extracts version via regex from the page.
- Custom: Allows complex logic like combining multiple regex matches or reformatting strings.
Used when version info is in HTTP headers (e.g., Content-Disposition or Location). The block receives |headers|.
Git strategy
Used for Git repositories. The block receives |tags| (an array of tag strings).
GithubLatest and GithubReleases strategies
Used for GitHub API interactions. The block receives |json, regex| (for GithubLatest) or |json| (for GithubReleases). You can inspect any field in the GitHub release JSON (e.g., tag_name, title, prerelease).
Crate strategy
Used for Rust crates. The block receives |json, regex| containing the registry API's versions data.
# PageMatch example: combining two regex matches
livecheck do
url "https://example.org/my-app/download"
regex(%r{href=.*?/(\d+)/MyApp-(\d+(?:\.\d+)*)\.zip}i)
strategy :page_match do |page, regex|
match = page.match(regex)
next if match.blank?
"#{match[2]},#{match[1]}"
end
end
# HeaderMatch example: using multiple headers
livecheck do
url "https://example.org/my-app/download/latest"
strategy :header_match do |headers|
v = headers["content-disposition"][/MyApp-(\d+(?:\.\d+)*)\.zip/i, 1]
id = headers["location"][%r{/(\d+)/download$}i, 1]
next if v.blank? || id.blank?
"#{v},#{id}"
end
end