From 77f94ba5bf67de5a6dbb063c7b9af59d32714175 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 18 May 2023 13:14:52 +0100 Subject: [PATCH] formulary: use a lot more `.presence`. Addresses regression in https://github.com/Homebrew/brew/pull/15396. Fixes https://github.com/Homebrew/homebrew-core/issues/131284 Fixes https://github.com/Homebrew/homebrew-core/issues/131287 Fixes https://github.com/Homebrew/homebrew-bundle/issues/1205 --- Library/Homebrew/formulary.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 34e5f0cc62..a0ccd011c0 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -155,7 +155,7 @@ module Formulary revision json_formula["revision"] version_scheme json_formula["version_scheme"] - if (urls_stable = json_formula["urls"]["stable"]).present? + if (urls_stable = json_formula["urls"]["stable"].presence) stable do url_spec = { tag: urls_stable["tag"], revision: urls_stable["revision"] }.compact url urls_stable["url"], **url_spec @@ -164,11 +164,11 @@ module Formulary end end - if (urls_head = json_formula["urls"]["head"]).present? + if (urls_head = json_formula["urls"]["head"].presence) head urls_head["url"], branch: urls_head["branch"] end - if (bottles_stable = json_formula["bottle"]["stable"]).present? + if (bottles_stable = json_formula["bottle"]["stable"].presence) bottle do if Homebrew::EnvConfig.bottle_domain == HOMEBREW_BOTTLE_DEFAULT_DOMAIN root_url HOMEBREW_BOTTLE_DEFAULT_DOMAIN @@ -183,17 +183,17 @@ module Formulary end end - if (keg_only_reason = json_formula["keg_only_reason"]).present? + if (keg_only_reason = json_formula["keg_only_reason"].presence) reason = Formulary.convert_to_string_or_symbol keg_only_reason["reason"] keg_only reason, keg_only_reason["explanation"] end - if (deprecation_date = json_formula["deprecation_date"]).present? + if (deprecation_date = json_formula["deprecation_date"].presence) reason = Formulary.convert_to_deprecate_disable_reason_string_or_symbol json_formula["deprecation_reason"] deprecate! date: deprecation_date, because: reason end - if (disable_date = json_formula["disable_date"]).present? + if (disable_date = json_formula["disable_date"].presence) reason = Formulary.convert_to_deprecate_disable_reason_string_or_symbol json_formula["disable_reason"] disable! date: disable_date, because: reason end @@ -258,12 +258,12 @@ module Formulary raise "Cannot build from source from abstract formula." end - if (service_hash = json_formula["service"]) + if (service_hash = json_formula["service"].presence) service_hash = Homebrew::Service.deserialize(service_hash) service do T.bind(self, Homebrew::Service) - if (run_params = service_hash.delete(:run)) + if (run_params = service_hash.delete(:run).presence) case run_params when Hash run(**run_params) @@ -272,7 +272,7 @@ module Formulary end end - if (name_params = service_hash.delete(:name)) + if (name_params = service_hash.delete(:name).presence) name(**name_params) end @@ -523,7 +523,7 @@ module Formulary curl_download url, to: path super rescue MethodDeprecatedError => e - if (match_data = url.match(%r{github.com/(?[\w-]+)/(?[\w-]+)/})) + if (match_data = url.match(%r{github.com/(?[\w-]+)/(?[\w-]+)/}).presence) e.issues_url = "https://github.com/#{match_data[:user]}/#{match_data[:repo]}/issues/new" end raise @@ -546,13 +546,13 @@ module Formulary if (possible_alias = tap.alias_dir/name).file? path = possible_alias.resolved_path name = path.basename(".rb").to_s - elsif (new_name = tap.formula_renames[name]) && + elsif (new_name = tap.formula_renames[name].presence) && (new_path = find_formula_from_name(new_name, tap)).file? old_name = name path = new_path name = new_name new_name = tap.core_tap? ? name : "#{tap}/#{name}" - elsif (new_tap_name = tap.tap_migrations[name]) + elsif (new_tap_name = tap.tap_migrations[name].presence) new_tap_user, new_tap_repo, = new_tap_name.split("/") new_tap_name = "#{new_tap_user}/#{new_tap_repo}" new_tap = Tap.fetch new_tap_name