Simplify strategies.
This commit is contained in:
parent
c306577575
commit
b8de4e8b21
@ -34,33 +34,33 @@ module Homebrew
|
|||||||
def self.find_versions(url, regex, &block)
|
def self.find_versions(url, regex, &block)
|
||||||
match_data = { matches: {}, regex: regex, url: url }
|
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 block
|
||||||
if regex
|
match = block.call(headers)
|
||||||
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])
|
|
||||||
else
|
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
|
end
|
||||||
|
|
||||||
match_data[:matches][version] = Version.new(version) if version
|
match_data[:matches][match] = Version.new(match) if match
|
||||||
|
|
||||||
match_data
|
match_data
|
||||||
end
|
end
|
||||||
|
|||||||
@ -27,9 +27,7 @@ module Homebrew
|
|||||||
|
|
||||||
if (item = item_from_content(contents))
|
if (item = item_from_content(contents))
|
||||||
match = if block
|
match = if block
|
||||||
item[:short_version] = item[:bundle_version]&.short_version
|
block.call(item)&.to_s
|
||||||
item[:version] = item[:bundle_version]&.version
|
|
||||||
block.call(item).to_s
|
|
||||||
else
|
else
|
||||||
item.bundle_version&.nice_version
|
item.bundle_version&.nice_version
|
||||||
end
|
end
|
||||||
@ -65,10 +63,14 @@ module Homebrew
|
|||||||
version ||= match[2]
|
version ||= match[2]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
bundle_version = BundleVersion.new(short_version, version) if short_version || version
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
title: title,
|
title: title,
|
||||||
url: url,
|
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
|
}.compact
|
||||||
|
|
||||||
Item.new(**data) unless data.empty?
|
Item.new(**data) unless data.empty?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user