Skip to content

Commit f02a48d

Browse files
committed
ExtractPlist: refactor URL options handling
This maintains the same behavior of the logic for handling `livecheck` block URL options but cleans it up a little. Namely: * Use trailing `if` in `filter_map` instead of ternary with `nil` branch. * Use `options` instead of `cask.livecheck.options`, as these are the same here. * Use `select` with a `nil?` guard instead of `compact.each` and pushing to an external variable, as this is a little tidier and uses less memory allocation.
1 parent 4fac1d8 commit f02a48d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Library/Homebrew/livecheck/strategy/extract_plist.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,21 @@ def self.find_versions(cask:, url: nil, regex: nil, options: Options.new, &block
107107
@cask_url_kw_params ||= T.let(
108108
T::Utils.signature_for_method(
109109
Cask::URL.instance_method(:initialize),
110-
).parameters.filter_map { |type, sym| (type == :key) ? sym : nil },
110+
).parameters.filter_map { |type, sym| sym if type == :key },
111111
T.nilable(T::Array[Symbol]),
112112
)
113113

114-
# Collect `livecheck` block options supported by `Cask::URL`
115-
url_kwargs = {}
114+
# Collect `livecheck` block URL options supported by `Cask::URL`
116115
unused_opts = []
117-
cask.livecheck.options.url_options.compact.each_key do |option_key|
118-
if @cask_url_kw_params.include?(option_key)
119-
url_kwargs[option_key] = cask.livecheck.options.public_send(option_key)
120-
else
121-
unused_opts << option_key
116+
url_kwargs = options.url_options.select do |key, value|
117+
next if value.nil?
118+
119+
unless @cask_url_kw_params.include?(key)
120+
unused_opts << key
121+
next
122122
end
123+
124+
true
123125
end
124126

125127
unless unused_opts.empty?
@@ -130,7 +132,7 @@ def self.find_versions(cask:, url: nil, regex: nil, options: Options.new, &block
130132
end
131133

132134
# Create a copy of the cask that overrides the artifact URL with the
133-
# provided URL and supported `livecheck` block options
135+
# provided URL and supported `livecheck` block URL options
134136
cask_copy = Cask::CaskLoader.load(cask.sourcefile_path)
135137
cask_copy.allow_reassignment = true
136138
cask_copy.url(url, **url_kwargs)

0 commit comments

Comments
 (0)