2024-07-04 20:09:36 -04:00
|
|
|
# typed: strict
|
2020-03-16 01:37:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-12-19 18:15:51 -05:00
|
|
|
require "livecheck/constants"
|
livecheck: Add Options class
This adds a `Livecheck::Options` class, which is intended to house
various configuration options that are set in `livecheck` blocks,
conditionally set by livecheck at runtime, etc. The general idea is
that when we add features involving configurations options (e.g., for
livecheck, strategies, curl, etc.), we can make changes to `Options`
without needing to modify parameters for strategy `find_versions`
methods, `Strategy` methods like `page_headers` and `page_content`,
etc. This is something that I've been trying to improve over the years
and `Options` should help to reduce maintenance overhead in this area
while also strengthening type signatures.
`Options` replaces the existing `homebrew_curl` option (which related
strategies pass to `Strategy` methods and on to `curl_args`) and the
new `url_options` (which contains `post_form` or `post_json` values
that are used to make `POST` requests). I recently added `url_options`
as a temporary way of enabling `POST` support without `Options` but
this restores the original `Options`-based implementation.
Along the way, I added a `homebrew_curl` parameter to the `url` DSL
method, allowing us to set an explicit value in `livecheck` blocks.
This is something that we've needed in some cases but I also intend
to replace implicit/inferred `homebrew_curl` usage with explicit
values in `livecheck` blocks once this is available for use. My
intention is to eventually remove the implicit behavior and only rely
on explicit values. That will align with how `homebrew_curl` options
work for other URLs and makes the behavior clear just from looking at
the `livecheck` block.
Lastly, this removes the `unused` rest parameter from `find_versions`
methods. I originally added `unused` as a way of handling parameters
that some `find_versions` methods have but others don't (e.g., `cask`
in `ExtractPlist`), as this allowed us to pass various arguments to
`find_versions` methods without worrying about whether a particular
parameter is available. This isn't an ideal solution and I originally
wanted to handle this situation by only passing expected arguments to
`find_versions` methods but there was a technical issue standing in
the way. I recently found an answer to the issue, so this also
replaces the existing `ExtractPlist` special case with generic logic
that checks the parameters for a strategy's `find_versions` method
and only passes expected arguments.
Replacing the aforementioned `find_versions` parameters with `Options`
ensures that the remaining parameters are fairly consistent across
strategies and any differences are handled by the aforementioned
logic. Outside of `ExtractPlist`, the only other difference is that
some `find_versions` methods have a `provided_content` parameter but
that's currently only used by tests (though it's intended for caching
support in the future). I will be renaming that parameter to `content`
in an upcoming PR and expanding it to the other strategies, which
should make them all consistent outside of `ExtractPlist`.
2025-02-11 18:04:38 -05:00
|
|
|
require "livecheck/options"
|
2024-07-14 08:49:39 -04:00
|
|
|
require "cask/cask"
|
2022-12-19 18:15:51 -05:00
|
|
|
|
2022-07-02 10:09:25 +02:00
|
|
|
# The {Livecheck} class implements the DSL methods used in a formula's, cask's
|
|
|
|
# or resource's `livecheck` block and stores related instance variables. Most
|
|
|
|
# of these methods also return the related instance variable when no argument
|
|
|
|
# is provided.
|
2020-08-07 17:27:31 -04:00
|
|
|
#
|
|
|
|
# This information is used by the `brew livecheck` command to control its
|
2021-01-11 17:12:48 -05:00
|
|
|
# behavior. Example `livecheck` blocks can be found in the
|
|
|
|
# [`brew livecheck` documentation](https://docs.brew.sh/Brew-Livecheck).
|
2020-03-16 01:37:49 +05:30
|
|
|
class Livecheck
|
2020-12-15 17:25:16 +01:00
|
|
|
extend Forwardable
|
|
|
|
|
livecheck: Add Options class
This adds a `Livecheck::Options` class, which is intended to house
various configuration options that are set in `livecheck` blocks,
conditionally set by livecheck at runtime, etc. The general idea is
that when we add features involving configurations options (e.g., for
livecheck, strategies, curl, etc.), we can make changes to `Options`
without needing to modify parameters for strategy `find_versions`
methods, `Strategy` methods like `page_headers` and `page_content`,
etc. This is something that I've been trying to improve over the years
and `Options` should help to reduce maintenance overhead in this area
while also strengthening type signatures.
`Options` replaces the existing `homebrew_curl` option (which related
strategies pass to `Strategy` methods and on to `curl_args`) and the
new `url_options` (which contains `post_form` or `post_json` values
that are used to make `POST` requests). I recently added `url_options`
as a temporary way of enabling `POST` support without `Options` but
this restores the original `Options`-based implementation.
Along the way, I added a `homebrew_curl` parameter to the `url` DSL
method, allowing us to set an explicit value in `livecheck` blocks.
This is something that we've needed in some cases but I also intend
to replace implicit/inferred `homebrew_curl` usage with explicit
values in `livecheck` blocks once this is available for use. My
intention is to eventually remove the implicit behavior and only rely
on explicit values. That will align with how `homebrew_curl` options
work for other URLs and makes the behavior clear just from looking at
the `livecheck` block.
Lastly, this removes the `unused` rest parameter from `find_versions`
methods. I originally added `unused` as a way of handling parameters
that some `find_versions` methods have but others don't (e.g., `cask`
in `ExtractPlist`), as this allowed us to pass various arguments to
`find_versions` methods without worrying about whether a particular
parameter is available. This isn't an ideal solution and I originally
wanted to handle this situation by only passing expected arguments to
`find_versions` methods but there was a technical issue standing in
the way. I recently found an answer to the issue, so this also
replaces the existing `ExtractPlist` special case with generic logic
that checks the parameters for a strategy's `find_versions` method
and only passes expected arguments.
Replacing the aforementioned `find_versions` parameters with `Options`
ensures that the remaining parameters are fairly consistent across
strategies and any differences are handled by the aforementioned
logic. Outside of `ExtractPlist`, the only other difference is that
some `find_versions` methods have a `provided_content` parameter but
that's currently only used by tests (though it's intended for caching
support in the future). I will be renaming that parameter to `content`
in an upcoming PR and expanding it to the other strategies, which
should make them all consistent outside of `ExtractPlist`.
2025-02-11 18:04:38 -05:00
|
|
|
# Options to modify livecheck's behavior.
|
|
|
|
sig { returns(Homebrew::Livecheck::Options) }
|
|
|
|
attr_reader :options
|
|
|
|
|
2022-07-02 10:09:25 +02:00
|
|
|
# A very brief description of why the formula/cask/resource is skipped (e.g.
|
|
|
|
# `No longer developed or maintained`).
|
2023-04-21 01:21:38 +02:00
|
|
|
sig { returns(T.nilable(String)) }
|
2020-03-16 01:37:49 +05:30
|
|
|
attr_reader :skip_msg
|
|
|
|
|
2025-02-04 10:30:16 -05:00
|
|
|
# A block used by strategies to identify version information.
|
|
|
|
sig { returns(T.nilable(Proc)) }
|
|
|
|
attr_reader :strategy_block
|
|
|
|
|
2023-04-21 01:21:38 +02:00
|
|
|
sig { params(package_or_resource: T.any(Cask::Cask, T.class_of(Formula), Resource)).void }
|
2022-07-02 10:09:25 +02:00
|
|
|
def initialize(package_or_resource)
|
|
|
|
@package_or_resource = package_or_resource
|
livecheck: Add Options class
This adds a `Livecheck::Options` class, which is intended to house
various configuration options that are set in `livecheck` blocks,
conditionally set by livecheck at runtime, etc. The general idea is
that when we add features involving configurations options (e.g., for
livecheck, strategies, curl, etc.), we can make changes to `Options`
without needing to modify parameters for strategy `find_versions`
methods, `Strategy` methods like `page_headers` and `page_content`,
etc. This is something that I've been trying to improve over the years
and `Options` should help to reduce maintenance overhead in this area
while also strengthening type signatures.
`Options` replaces the existing `homebrew_curl` option (which related
strategies pass to `Strategy` methods and on to `curl_args`) and the
new `url_options` (which contains `post_form` or `post_json` values
that are used to make `POST` requests). I recently added `url_options`
as a temporary way of enabling `POST` support without `Options` but
this restores the original `Options`-based implementation.
Along the way, I added a `homebrew_curl` parameter to the `url` DSL
method, allowing us to set an explicit value in `livecheck` blocks.
This is something that we've needed in some cases but I also intend
to replace implicit/inferred `homebrew_curl` usage with explicit
values in `livecheck` blocks once this is available for use. My
intention is to eventually remove the implicit behavior and only rely
on explicit values. That will align with how `homebrew_curl` options
work for other URLs and makes the behavior clear just from looking at
the `livecheck` block.
Lastly, this removes the `unused` rest parameter from `find_versions`
methods. I originally added `unused` as a way of handling parameters
that some `find_versions` methods have but others don't (e.g., `cask`
in `ExtractPlist`), as this allowed us to pass various arguments to
`find_versions` methods without worrying about whether a particular
parameter is available. This isn't an ideal solution and I originally
wanted to handle this situation by only passing expected arguments to
`find_versions` methods but there was a technical issue standing in
the way. I recently found an answer to the issue, so this also
replaces the existing `ExtractPlist` special case with generic logic
that checks the parameters for a strategy's `find_versions` method
and only passes expected arguments.
Replacing the aforementioned `find_versions` parameters with `Options`
ensures that the remaining parameters are fairly consistent across
strategies and any differences are handled by the aforementioned
logic. Outside of `ExtractPlist`, the only other difference is that
some `find_versions` methods have a `provided_content` parameter but
that's currently only used by tests (though it's intended for caching
support in the future). I will be renaming that parameter to `content`
in an upcoming PR and expanding it to the other strategies, which
should make them all consistent outside of `ExtractPlist`.
2025-02-11 18:04:38 -05:00
|
|
|
@options = T.let(Homebrew::Livecheck::Options.new, Homebrew::Livecheck::Options)
|
2024-07-04 20:09:36 -04:00
|
|
|
@referenced_cask_name = T.let(nil, T.nilable(String))
|
|
|
|
@referenced_formula_name = T.let(nil, T.nilable(String))
|
|
|
|
@regex = T.let(nil, T.nilable(Regexp))
|
|
|
|
@skip = T.let(false, T::Boolean)
|
|
|
|
@skip_msg = T.let(nil, T.nilable(String))
|
|
|
|
@strategy = T.let(nil, T.nilable(Symbol))
|
|
|
|
@strategy_block = T.let(nil, T.nilable(Proc))
|
|
|
|
@throttle = T.let(nil, T.nilable(Integer))
|
|
|
|
@url = T.let(nil, T.any(NilClass, String, Symbol))
|
2020-03-16 01:37:49 +05:30
|
|
|
end
|
|
|
|
|
2021-07-19 11:21:29 -04:00
|
|
|
# Sets the `@referenced_cask_name` instance variable to the provided `String`
|
|
|
|
# or returns the `@referenced_cask_name` instance variable when no argument
|
|
|
|
# is provided. Inherited livecheck values from the referenced cask
|
2024-12-02 10:06:14 -05:00
|
|
|
# (e.g. regex) can be overridden in the `livecheck` block.
|
2023-04-21 01:21:38 +02:00
|
|
|
sig {
|
|
|
|
params(
|
|
|
|
# Name of cask to inherit livecheck info from.
|
|
|
|
cask_name: String,
|
|
|
|
).returns(T.nilable(String))
|
|
|
|
}
|
|
|
|
def cask(cask_name = T.unsafe(nil))
|
2021-07-19 11:21:29 -04:00
|
|
|
case cask_name
|
|
|
|
when nil
|
|
|
|
@referenced_cask_name
|
|
|
|
when String
|
|
|
|
@referenced_cask_name = cask_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Sets the `@referenced_formula_name` instance variable to the provided
|
2025-01-07 01:57:42 +05:30
|
|
|
# `String`/`Symbol` or returns the `@referenced_formula_name` instance
|
|
|
|
# variable when no argument is provided. Inherited livecheck values from the
|
|
|
|
# referenced formula (e.g. regex) can be overridden in the `livecheck` block.
|
2023-04-21 01:21:38 +02:00
|
|
|
sig {
|
|
|
|
params(
|
|
|
|
# Name of formula to inherit livecheck info from.
|
2025-01-06 12:56:25 +05:30
|
|
|
formula_name: T.any(String, Symbol),
|
|
|
|
).returns(T.nilable(T.any(String, Symbol)))
|
2023-04-21 01:21:38 +02:00
|
|
|
}
|
|
|
|
def formula(formula_name = T.unsafe(nil))
|
2021-07-19 11:21:29 -04:00
|
|
|
case formula_name
|
|
|
|
when nil
|
|
|
|
@referenced_formula_name
|
2025-01-06 12:56:25 +05:30
|
|
|
when String, :parent
|
2021-07-19 11:21:29 -04:00
|
|
|
@referenced_formula_name = formula_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-07 17:27:31 -04:00
|
|
|
# Sets the `@regex` instance variable to the provided `Regexp` or returns the
|
|
|
|
# `@regex` instance variable when no argument is provided.
|
2023-04-21 01:21:38 +02:00
|
|
|
sig {
|
|
|
|
params(
|
|
|
|
# Regex to use for matching versions in content.
|
|
|
|
pattern: Regexp,
|
|
|
|
).returns(T.nilable(Regexp))
|
|
|
|
}
|
|
|
|
def regex(pattern = T.unsafe(nil))
|
2020-08-07 17:25:08 -04:00
|
|
|
case pattern
|
|
|
|
when nil
|
|
|
|
@regex
|
|
|
|
when Regexp
|
|
|
|
@regex = pattern
|
|
|
|
end
|
2020-03-16 01:37:49 +05:30
|
|
|
end
|
|
|
|
|
2020-08-07 17:27:31 -04:00
|
|
|
# Sets the `@skip` instance variable to `true` and sets the `@skip_msg`
|
|
|
|
# instance variable if a `String` is provided. `@skip` is used to indicate
|
2022-07-02 10:09:25 +02:00
|
|
|
# that the formula/cask/resource should be skipped and the `skip_msg` very
|
|
|
|
# briefly describes why it is skipped (e.g. "No longer developed or
|
|
|
|
# maintained").
|
2023-04-21 01:21:38 +02:00
|
|
|
sig {
|
|
|
|
params(
|
|
|
|
# String describing why the formula/cask is skipped.
|
|
|
|
skip_msg: String,
|
|
|
|
).returns(T::Boolean)
|
|
|
|
}
|
|
|
|
def skip(skip_msg = T.unsafe(nil))
|
|
|
|
@skip_msg = skip_msg if skip_msg.is_a?(String)
|
2020-08-07 17:25:08 -04:00
|
|
|
|
2020-03-16 01:37:49 +05:30
|
|
|
@skip = true
|
|
|
|
end
|
|
|
|
|
2022-07-02 10:09:25 +02:00
|
|
|
# Should `livecheck` skip this formula/cask/resource?
|
2023-04-21 01:21:38 +02:00
|
|
|
sig { returns(T::Boolean) }
|
2020-03-16 01:37:49 +05:30
|
|
|
def skip?
|
|
|
|
@skip
|
|
|
|
end
|
|
|
|
|
2020-08-07 17:27:31 -04:00
|
|
|
# Sets the `@strategy` instance variable to the provided `Symbol` or returns
|
|
|
|
# the `@strategy` instance variable when no argument is provided. The strategy
|
2020-11-05 17:17:03 -05:00
|
|
|
# symbols use snake case (e.g. `:page_match`) and correspond to the strategy
|
2020-08-05 11:54:37 -04:00
|
|
|
# file name.
|
2023-04-21 01:21:38 +02:00
|
|
|
sig {
|
|
|
|
params(
|
|
|
|
# Symbol for the desired strategy.
|
|
|
|
symbol: Symbol,
|
|
|
|
block: T.nilable(Proc),
|
|
|
|
).returns(T.nilable(Symbol))
|
|
|
|
}
|
|
|
|
def strategy(symbol = T.unsafe(nil), &block)
|
2020-12-13 12:23:20 +01:00
|
|
|
@strategy_block = block if block
|
|
|
|
|
2020-08-05 11:54:37 -04:00
|
|
|
case symbol
|
|
|
|
when nil
|
|
|
|
@strategy
|
|
|
|
when Symbol
|
|
|
|
@strategy = symbol
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-03-21 08:19:35 -04:00
|
|
|
# Sets the `@throttle` instance variable to the provided `Integer` or returns
|
|
|
|
# the `@throttle` instance variable when no argument is provided.
|
|
|
|
sig {
|
|
|
|
params(
|
|
|
|
# Throttle rate of version patch number to use for bumpable versions.
|
2024-03-21 08:37:27 -04:00
|
|
|
rate: Integer,
|
2024-03-21 08:19:35 -04:00
|
|
|
).returns(T.nilable(Integer))
|
|
|
|
}
|
|
|
|
def throttle(rate = T.unsafe(nil))
|
|
|
|
case rate
|
|
|
|
when nil
|
|
|
|
@throttle
|
|
|
|
when Integer
|
|
|
|
@throttle = rate
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-07 17:27:31 -04:00
|
|
|
# Sets the `@url` instance variable to the provided argument or returns the
|
|
|
|
# `@url` instance variable when no argument is provided. The argument can be
|
|
|
|
# a `String` (a URL) or a supported `Symbol` corresponding to a URL in the
|
2022-07-02 10:09:25 +02:00
|
|
|
# formula/cask/resource (e.g. `:stable`, `:homepage`, `:head`, `:url`).
|
2025-02-04 10:30:16 -05:00
|
|
|
# Any options provided to the method are passed through to `Strategy` methods
|
|
|
|
# (`page_headers`, `page_content`).
|
2023-04-21 01:21:38 +02:00
|
|
|
sig {
|
|
|
|
params(
|
|
|
|
# URL to check for version information.
|
livecheck: Add Options class
This adds a `Livecheck::Options` class, which is intended to house
various configuration options that are set in `livecheck` blocks,
conditionally set by livecheck at runtime, etc. The general idea is
that when we add features involving configurations options (e.g., for
livecheck, strategies, curl, etc.), we can make changes to `Options`
without needing to modify parameters for strategy `find_versions`
methods, `Strategy` methods like `page_headers` and `page_content`,
etc. This is something that I've been trying to improve over the years
and `Options` should help to reduce maintenance overhead in this area
while also strengthening type signatures.
`Options` replaces the existing `homebrew_curl` option (which related
strategies pass to `Strategy` methods and on to `curl_args`) and the
new `url_options` (which contains `post_form` or `post_json` values
that are used to make `POST` requests). I recently added `url_options`
as a temporary way of enabling `POST` support without `Options` but
this restores the original `Options`-based implementation.
Along the way, I added a `homebrew_curl` parameter to the `url` DSL
method, allowing us to set an explicit value in `livecheck` blocks.
This is something that we've needed in some cases but I also intend
to replace implicit/inferred `homebrew_curl` usage with explicit
values in `livecheck` blocks once this is available for use. My
intention is to eventually remove the implicit behavior and only rely
on explicit values. That will align with how `homebrew_curl` options
work for other URLs and makes the behavior clear just from looking at
the `livecheck` block.
Lastly, this removes the `unused` rest parameter from `find_versions`
methods. I originally added `unused` as a way of handling parameters
that some `find_versions` methods have but others don't (e.g., `cask`
in `ExtractPlist`), as this allowed us to pass various arguments to
`find_versions` methods without worrying about whether a particular
parameter is available. This isn't an ideal solution and I originally
wanted to handle this situation by only passing expected arguments to
`find_versions` methods but there was a technical issue standing in
the way. I recently found an answer to the issue, so this also
replaces the existing `ExtractPlist` special case with generic logic
that checks the parameters for a strategy's `find_versions` method
and only passes expected arguments.
Replacing the aforementioned `find_versions` parameters with `Options`
ensures that the remaining parameters are fairly consistent across
strategies and any differences are handled by the aforementioned
logic. Outside of `ExtractPlist`, the only other difference is that
some `find_versions` methods have a `provided_content` parameter but
that's currently only used by tests (though it's intended for caching
support in the future). I will be renaming that parameter to `content`
in an upcoming PR and expanding it to the other strategies, which
should make them all consistent outside of `ExtractPlist`.
2025-02-11 18:04:38 -05:00
|
|
|
url: T.any(String, Symbol),
|
|
|
|
homebrew_curl: T.nilable(T::Boolean),
|
|
|
|
post_form: T.nilable(T::Hash[Symbol, String]),
|
2025-03-17 08:15:43 +01:00
|
|
|
post_json: T.nilable(T::Hash[Symbol, T.anything]),
|
2023-04-21 01:21:38 +02:00
|
|
|
).returns(T.nilable(T.any(String, Symbol)))
|
|
|
|
}
|
livecheck: Add Options class
This adds a `Livecheck::Options` class, which is intended to house
various configuration options that are set in `livecheck` blocks,
conditionally set by livecheck at runtime, etc. The general idea is
that when we add features involving configurations options (e.g., for
livecheck, strategies, curl, etc.), we can make changes to `Options`
without needing to modify parameters for strategy `find_versions`
methods, `Strategy` methods like `page_headers` and `page_content`,
etc. This is something that I've been trying to improve over the years
and `Options` should help to reduce maintenance overhead in this area
while also strengthening type signatures.
`Options` replaces the existing `homebrew_curl` option (which related
strategies pass to `Strategy` methods and on to `curl_args`) and the
new `url_options` (which contains `post_form` or `post_json` values
that are used to make `POST` requests). I recently added `url_options`
as a temporary way of enabling `POST` support without `Options` but
this restores the original `Options`-based implementation.
Along the way, I added a `homebrew_curl` parameter to the `url` DSL
method, allowing us to set an explicit value in `livecheck` blocks.
This is something that we've needed in some cases but I also intend
to replace implicit/inferred `homebrew_curl` usage with explicit
values in `livecheck` blocks once this is available for use. My
intention is to eventually remove the implicit behavior and only rely
on explicit values. That will align with how `homebrew_curl` options
work for other URLs and makes the behavior clear just from looking at
the `livecheck` block.
Lastly, this removes the `unused` rest parameter from `find_versions`
methods. I originally added `unused` as a way of handling parameters
that some `find_versions` methods have but others don't (e.g., `cask`
in `ExtractPlist`), as this allowed us to pass various arguments to
`find_versions` methods without worrying about whether a particular
parameter is available. This isn't an ideal solution and I originally
wanted to handle this situation by only passing expected arguments to
`find_versions` methods but there was a technical issue standing in
the way. I recently found an answer to the issue, so this also
replaces the existing `ExtractPlist` special case with generic logic
that checks the parameters for a strategy's `find_versions` method
and only passes expected arguments.
Replacing the aforementioned `find_versions` parameters with `Options`
ensures that the remaining parameters are fairly consistent across
strategies and any differences are handled by the aforementioned
logic. Outside of `ExtractPlist`, the only other difference is that
some `find_versions` methods have a `provided_content` parameter but
that's currently only used by tests (though it's intended for caching
support in the future). I will be renaming that parameter to `content`
in an upcoming PR and expanding it to the other strategies, which
should make them all consistent outside of `ExtractPlist`.
2025-02-11 18:04:38 -05:00
|
|
|
def url(url = T.unsafe(nil), homebrew_curl: nil, post_form: nil, post_json: nil)
|
2025-02-04 10:30:16 -05:00
|
|
|
raise ArgumentError, "Only use `post_form` or `post_json`, not both" if post_form && post_json
|
|
|
|
|
2025-02-13 21:32:51 -05:00
|
|
|
@options.homebrew_curl = homebrew_curl unless homebrew_curl.nil?
|
|
|
|
@options.post_form = post_form unless post_form.nil?
|
|
|
|
@options.post_json = post_json unless post_json.nil?
|
2025-02-04 10:30:16 -05:00
|
|
|
|
2023-04-21 01:21:38 +02:00
|
|
|
case url
|
2020-08-07 17:25:08 -04:00
|
|
|
when nil
|
2021-01-12 15:00:49 -05:00
|
|
|
@url
|
|
|
|
when String, :head, :homepage, :stable, :url
|
2023-04-21 01:21:38 +02:00
|
|
|
@url = url
|
|
|
|
when Symbol
|
|
|
|
raise ArgumentError, "#{url.inspect} is not a valid URL shorthand"
|
2020-05-31 00:10:46 +05:30
|
|
|
end
|
2020-03-16 01:37:49 +05:30
|
|
|
end
|
|
|
|
|
livecheck: Add Options class
This adds a `Livecheck::Options` class, which is intended to house
various configuration options that are set in `livecheck` blocks,
conditionally set by livecheck at runtime, etc. The general idea is
that when we add features involving configurations options (e.g., for
livecheck, strategies, curl, etc.), we can make changes to `Options`
without needing to modify parameters for strategy `find_versions`
methods, `Strategy` methods like `page_headers` and `page_content`,
etc. This is something that I've been trying to improve over the years
and `Options` should help to reduce maintenance overhead in this area
while also strengthening type signatures.
`Options` replaces the existing `homebrew_curl` option (which related
strategies pass to `Strategy` methods and on to `curl_args`) and the
new `url_options` (which contains `post_form` or `post_json` values
that are used to make `POST` requests). I recently added `url_options`
as a temporary way of enabling `POST` support without `Options` but
this restores the original `Options`-based implementation.
Along the way, I added a `homebrew_curl` parameter to the `url` DSL
method, allowing us to set an explicit value in `livecheck` blocks.
This is something that we've needed in some cases but I also intend
to replace implicit/inferred `homebrew_curl` usage with explicit
values in `livecheck` blocks once this is available for use. My
intention is to eventually remove the implicit behavior and only rely
on explicit values. That will align with how `homebrew_curl` options
work for other URLs and makes the behavior clear just from looking at
the `livecheck` block.
Lastly, this removes the `unused` rest parameter from `find_versions`
methods. I originally added `unused` as a way of handling parameters
that some `find_versions` methods have but others don't (e.g., `cask`
in `ExtractPlist`), as this allowed us to pass various arguments to
`find_versions` methods without worrying about whether a particular
parameter is available. This isn't an ideal solution and I originally
wanted to handle this situation by only passing expected arguments to
`find_versions` methods but there was a technical issue standing in
the way. I recently found an answer to the issue, so this also
replaces the existing `ExtractPlist` special case with generic logic
that checks the parameters for a strategy's `find_versions` method
and only passes expected arguments.
Replacing the aforementioned `find_versions` parameters with `Options`
ensures that the remaining parameters are fairly consistent across
strategies and any differences are handled by the aforementioned
logic. Outside of `ExtractPlist`, the only other difference is that
some `find_versions` methods have a `provided_content` parameter but
that's currently only used by tests (though it's intended for caching
support in the future). I will be renaming that parameter to `content`
in an upcoming PR and expanding it to the other strategies, which
should make them all consistent outside of `ExtractPlist`.
2025-02-11 18:04:38 -05:00
|
|
|
delegate url_options: :@options
|
2022-08-05 15:51:02 -04:00
|
|
|
delegate arch: :@package_or_resource
|
2025-04-03 19:28:02 -04:00
|
|
|
delegate os: :@package_or_resource
|
|
|
|
delegate version: :@package_or_resource
|
|
|
|
private :arch, :os, :version
|
2020-08-07 17:27:31 -04:00
|
|
|
# Returns a `Hash` of all instance variable values.
|
|
|
|
# @return [Hash]
|
2023-04-21 01:21:38 +02:00
|
|
|
sig { returns(T::Hash[String, T.untyped]) }
|
2020-03-16 01:37:49 +05:30
|
|
|
def to_hash
|
|
|
|
{
|
livecheck: Add Options class
This adds a `Livecheck::Options` class, which is intended to house
various configuration options that are set in `livecheck` blocks,
conditionally set by livecheck at runtime, etc. The general idea is
that when we add features involving configurations options (e.g., for
livecheck, strategies, curl, etc.), we can make changes to `Options`
without needing to modify parameters for strategy `find_versions`
methods, `Strategy` methods like `page_headers` and `page_content`,
etc. This is something that I've been trying to improve over the years
and `Options` should help to reduce maintenance overhead in this area
while also strengthening type signatures.
`Options` replaces the existing `homebrew_curl` option (which related
strategies pass to `Strategy` methods and on to `curl_args`) and the
new `url_options` (which contains `post_form` or `post_json` values
that are used to make `POST` requests). I recently added `url_options`
as a temporary way of enabling `POST` support without `Options` but
this restores the original `Options`-based implementation.
Along the way, I added a `homebrew_curl` parameter to the `url` DSL
method, allowing us to set an explicit value in `livecheck` blocks.
This is something that we've needed in some cases but I also intend
to replace implicit/inferred `homebrew_curl` usage with explicit
values in `livecheck` blocks once this is available for use. My
intention is to eventually remove the implicit behavior and only rely
on explicit values. That will align with how `homebrew_curl` options
work for other URLs and makes the behavior clear just from looking at
the `livecheck` block.
Lastly, this removes the `unused` rest parameter from `find_versions`
methods. I originally added `unused` as a way of handling parameters
that some `find_versions` methods have but others don't (e.g., `cask`
in `ExtractPlist`), as this allowed us to pass various arguments to
`find_versions` methods without worrying about whether a particular
parameter is available. This isn't an ideal solution and I originally
wanted to handle this situation by only passing expected arguments to
`find_versions` methods but there was a technical issue standing in
the way. I recently found an answer to the issue, so this also
replaces the existing `ExtractPlist` special case with generic logic
that checks the parameters for a strategy's `find_versions` method
and only passes expected arguments.
Replacing the aforementioned `find_versions` parameters with `Options`
ensures that the remaining parameters are fairly consistent across
strategies and any differences are handled by the aforementioned
logic. Outside of `ExtractPlist`, the only other difference is that
some `find_versions` methods have a `provided_content` parameter but
that's currently only used by tests (though it's intended for caching
support in the future). I will be renaming that parameter to `content`
in an upcoming PR and expanding it to the other strategies, which
should make them all consistent outside of `ExtractPlist`.
2025-02-11 18:04:38 -05:00
|
|
|
"options" => @options.to_hash,
|
|
|
|
"cask" => @referenced_cask_name,
|
|
|
|
"formula" => @referenced_formula_name,
|
|
|
|
"regex" => @regex,
|
|
|
|
"skip" => @skip,
|
|
|
|
"skip_msg" => @skip_msg,
|
|
|
|
"strategy" => @strategy,
|
|
|
|
"throttle" => @throttle,
|
|
|
|
"url" => @url,
|
2020-03-16 01:37:49 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|