From 2ad87f87d5130a2ab6b9c4a471b69b06c2fa2617 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Wed, 2 Aug 2023 09:44:18 -0700 Subject: [PATCH] Make inreplace a purely static method --- Library/Homebrew/cask/migrator.rb | 4 +--- Library/Homebrew/formula.rb | 3 +-- Library/Homebrew/utils/inreplace.rb | 6 ++---- Library/Homebrew/utils/inreplace.rbi | 7 ------- 4 files changed, 4 insertions(+), 16 deletions(-) delete mode 100644 Library/Homebrew/utils/inreplace.rbi diff --git a/Library/Homebrew/cask/migrator.rb b/Library/Homebrew/cask/migrator.rb index d850627706..1c3d9f4f20 100644 --- a/Library/Homebrew/cask/migrator.rb +++ b/Library/Homebrew/cask/migrator.rb @@ -6,8 +6,6 @@ require "utils/inreplace" module Cask class Migrator - extend ::Utils::Inreplace - attr_reader :old_cask, :new_cask sig { params(old_cask: Cask, new_cask: Cask).void } @@ -74,7 +72,7 @@ module Cask def self.replace_caskfile_token(path, old_token, new_token) case path.extname when ".rb" - inreplace path, /\A\s*cask\s+"#{Regexp.escape(old_token)}"/, "cask #{new_token.inspect}" + ::Utils::Inreplace.inreplace path, /\A\s*cask\s+"#{Regexp.escape(old_token)}"/, "cask #{new_token.inspect}" when ".json" json = JSON.parse(path.read) json["token"] = new_token diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 738000ff6f..3ba036d11f 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -59,7 +59,6 @@ require "extend/api_hashable" # end class Formula include FileUtils - include Utils::Inreplace include Utils::Shebang include Utils::Shell include Context @@ -2563,7 +2562,7 @@ class Formula ).void } def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter - super(paths, before, after, audit_result) + Utils::Inreplace.inreplace(paths, before, after, audit_result) rescue Utils::Inreplace::Error => e onoe e.to_s raise BuildError.new(self, "inreplace", Array(paths), {}) diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index 5f51f78169..4515bcfa23 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -18,8 +18,6 @@ module Utils end end - module_function - # Sometimes we have to change a bit before we install. Mostly we # prefer a patch, but if you need the {Formula#prefix prefix} of # this formula in the patch you have to resort to `inreplace`, @@ -45,7 +43,7 @@ module Utils audit_result: T::Boolean, ).void } - def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter + def self.inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter paths = Array(paths) after &&= after.to_s before = before.to_s if before.is_a?(Pathname) @@ -73,7 +71,7 @@ module Utils end # @api private - def inreplace_pairs(path, replacement_pairs, read_only_run: false, silent: false) + def self.inreplace_pairs(path, replacement_pairs, read_only_run: false, silent: false) str = File.binread(path) contents = StringInreplaceExtension.new(str) replacement_pairs.each do |old, new| diff --git a/Library/Homebrew/utils/inreplace.rbi b/Library/Homebrew/utils/inreplace.rbi deleted file mode 100644 index 02542091d2..0000000000 --- a/Library/Homebrew/utils/inreplace.rbi +++ /dev/null @@ -1,7 +0,0 @@ -# typed: strict - -module Utils - module Inreplace - include Kernel - end -end