Refactor #find_versions parameters in strategies #11854
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?Livecheck's strategies all contain a
#find_versions
method that takes input (e.g., aurl
,regex
,cask
, etc.) and uses it to identify versions from a source. All of the strategies except forExtractPlist
expect that a URL will be provided.ExtractPlist
is an exception (in many unfortunate ways), as it expects a cask instead of a URL.When
ExtractPlist
was created, acask
parameter was added to every#find_version
method. This is because livecheck uses all the possible arguments when it calls the method, regardless of the strategy (i.e., it doesn't cater the arguments to what the strategy expects). If a strategy didn't have thecask
parameter but a namedcask
argument was provided, Ruby would give an error.Ideally, a given
#find_versions
method should only be required to have parameters for what it actually uses and we shouldn't have to update every method if one strategy needs a new parameter. This PR aims to achieve this by removing unused parameters from#find_versions
methods and including an**unused
parameter in each, as the double splat will take care of any arguments that don't correspond to a named parameter for a given strategy.For example,
ExtractPlist
has a namedcask:
parameter (since it's the only strategy that works with a cask) but all the others omit this. Instead of producing an error, thecask
parameter is simply part ofunused
(i.e.,unused[:cask]
).In general, this helps to minimize
#find_versions
parameters to only what's used. This will make it easier to add new strategies in the future, where a new parameter wouldn't need to be added to all other strategies. Besides that, this bit of clean up helps to make things a bit more manageable before I add a couple more parameters to most#find_versions
methods in the near future.As usual, I've done comparative before/after livecheck runs across first-party formulae/casks and I didn't see any regressions.