Simplify strategies.

This commit is contained in:
Markus Reiter 2020-12-18 21:17:55 +01:00 committed by Sam Ford
parent c306577575
commit b8de4e8b21
No known key found for this signature in database
GPG Key ID: 95209E46C7FFDEFE
2 changed files with 29 additions and 27 deletions

View File

@ -34,33 +34,33 @@ module Homebrew
def self.find_versions(url, regex, &block)
match_data = { matches: {}, regex: regex, url: url }
data = { headers: Strategy.page_headers(url) }
headers = Strategy.page_headers(url)
if (filename = data[:headers]["content-disposition"])
if regex
data[:version] ||= location[regex, 1]
else
v = Version.parse(filename, detected_from_url: true)
data[:version] ||= v.to_s unless v.null?
end
end
if (location = data[:headers]["location"])
if regex
data[:version] ||= location[regex, 1]
else
v = Version.parse(location, detected_from_url: true)
data[:version] ||= v.to_s unless v.null?
end
end
version = if block
block.call(data[:headers])
if block
match = block.call(headers)
else
data[:version]
match = nil
if (filename = headers["content-disposition"])
if regex
match ||= location[regex, 1]
else
v = Version.parse(filename, detected_from_url: true)
match ||= v.to_s unless v.null?
end
end
if (location = headers["location"])
if regex
match ||= location[regex, 1]
else
v = Version.parse(location, detected_from_url: true)
match ||= v.to_s unless v.null?
end
end
end
match_data[:matches][version] = Version.new(version) if version
match_data[:matches][match] = Version.new(match) if match
match_data
end

View File

@ -27,9 +27,7 @@ module Homebrew
if (item = item_from_content(contents))
match = if block
item[:short_version] = item[:bundle_version]&.short_version
item[:version] = item[:bundle_version]&.version
block.call(item).to_s
block.call(item)&.to_s
else
item.bundle_version&.nice_version
end
@ -65,10 +63,14 @@ module Homebrew
version ||= match[2]
end
bundle_version = BundleVersion.new(short_version, version) if short_version || version
data = {
title: title,
url: url,
bundle_version: short_version || version ? BundleVersion.new(short_version, version) : nil,
bundle_version: bundle_version,
short_version: bundle_version&.short_version,
version: bundle_version&.version,
}.compact
Item.new(**data) unless data.empty?