From 55ec4c483cdb2ad0d4ffb8cf507ef2412414b160 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Thu, 8 Feb 2024 17:30:11 -0500 Subject: [PATCH] Crate: Rework conditions Co-authored-by: Douglas Eichelberger Co-authored-by: Markus Reiter --- Library/Homebrew/livecheck/strategy/crate.rb | 14 +++++--------- docs/Brew-Livecheck.md | 4 ++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/livecheck/strategy/crate.rb b/Library/Homebrew/livecheck/strategy/crate.rb index 2b5d04898e..b9bfd37a6e 100644 --- a/Library/Homebrew/livecheck/strategy/crate.rb +++ b/Library/Homebrew/livecheck/strategy/crate.rb @@ -25,10 +25,8 @@ module Homebrew # a `strategy` block isn't provided. DEFAULT_BLOCK = proc do |json, regex| json["versions"]&.map do |version| - next if version["yanked"] == true - - match = version["num"]&.match(regex) - next if match.blank? + next if version["yanked"] + next unless (match = version["num"]&.match(regex)) match[1] end @@ -58,9 +56,7 @@ module Homebrew sig { params(url: String).returns(T::Hash[Symbol, T.untyped]) } def self.generate_input_values(url) values = {} - - match = url.match(URL_MATCH_REGEX) - return values if match.blank? + return values unless (match = url.match(URL_MATCH_REGEX)) values[:url] = "https://crates.io/api/v1/crates/#{match[:package]}/versions" @@ -95,13 +91,13 @@ module Homebrew match_data[:url] = generated[:url] - content = if provided_content.is_a?(String) + content = if provided_content provided_content else match_data.merge!(Strategy.page_content(match_data[:url], homebrew_curl: homebrew_curl)) match_data[:content] end - return match_data if content.blank? + return match_data unless content Json.versions_from_content(content, regex || DEFAULT_REGEX, &block || DEFAULT_BLOCK).each do |match_text| match_data[:matches][match_text] = Version.new(match_text) diff --git a/docs/Brew-Livecheck.md b/docs/Brew-Livecheck.md index 07ca49b159..36cfce54bf 100644 --- a/docs/Brew-Livecheck.md +++ b/docs/Brew-Livecheck.md @@ -248,8 +248,8 @@ livecheck do url :stable strategy :crate do |json, regex| json["versions"]&.map do |version| - next if version["yanked"] == true - next if (match = version["num"]&.match(regex)).blank? + next if version["yanked"] + next unless (match = version["num"]&.match(regex)) match[1] end