From b8de4e8b21e7daf40c805e1f1058eae7393d06e1 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 18 Dec 2020 21:17:55 +0100 Subject: [PATCH] Simplify strategies. --- .../livecheck/strategy/header_match.rb | 46 +++++++++---------- .../Homebrew/livecheck/strategy/sparkle.rb | 10 ++-- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Library/Homebrew/livecheck/strategy/header_match.rb b/Library/Homebrew/livecheck/strategy/header_match.rb index f07103cc9a..e307f9dec1 100644 --- a/Library/Homebrew/livecheck/strategy/header_match.rb +++ b/Library/Homebrew/livecheck/strategy/header_match.rb @@ -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 diff --git a/Library/Homebrew/livecheck/strategy/sparkle.rb b/Library/Homebrew/livecheck/strategy/sparkle.rb index 7fad9e885a..eb0877c279 100644 --- a/Library/Homebrew/livecheck/strategy/sparkle.rb +++ b/Library/Homebrew/livecheck/strategy/sparkle.rb @@ -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?