Revert "Make inreplace a purely static method"
				
					
				
			This commit is contained in:
		
							parent
							
								
									24b6b3494d
								
							
						
					
					
						commit
						8656caa67c
					
				@ -6,6 +6,8 @@ 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 }
 | 
			
		||||
@ -72,7 +74,7 @@ module Cask
 | 
			
		||||
    def self.replace_caskfile_token(path, old_token, new_token)
 | 
			
		||||
      case path.extname
 | 
			
		||||
      when ".rb"
 | 
			
		||||
        ::Utils::Inreplace.inreplace path, /\A\s*cask\s+"#{Regexp.escape(old_token)}"/, "cask #{new_token.inspect}"
 | 
			
		||||
        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
 | 
			
		||||
 | 
			
		||||
@ -59,6 +59,7 @@ require "extend/api_hashable"
 | 
			
		||||
# end</pre>
 | 
			
		||||
class Formula
 | 
			
		||||
  include FileUtils
 | 
			
		||||
  include Utils::Inreplace
 | 
			
		||||
  include Utils::Shebang
 | 
			
		||||
  include Utils::Shell
 | 
			
		||||
  include Context
 | 
			
		||||
@ -2562,7 +2563,7 @@ class Formula
 | 
			
		||||
    ).void
 | 
			
		||||
  }
 | 
			
		||||
  def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
 | 
			
		||||
    Utils::Inreplace.inreplace(paths, before, after, audit_result: audit_result)
 | 
			
		||||
    super(paths, before, after, audit_result)
 | 
			
		||||
  rescue Utils::Inreplace::Error => e
 | 
			
		||||
    onoe e.to_s
 | 
			
		||||
    raise BuildError.new(self, "inreplace", Array(paths), {})
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,8 @@ 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`,
 | 
			
		||||
@ -43,7 +45,7 @@ module Utils
 | 
			
		||||
        audit_result: T::Boolean,
 | 
			
		||||
      ).void
 | 
			
		||||
    }
 | 
			
		||||
    def self.inreplace(paths, before = nil, after = nil, audit_result: true)
 | 
			
		||||
    def 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)
 | 
			
		||||
@ -71,7 +73,7 @@ module Utils
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # @api private
 | 
			
		||||
    def self.inreplace_pairs(path, replacement_pairs, read_only_run: false, silent: false)
 | 
			
		||||
    def 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|
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										7
									
								
								Library/Homebrew/utils/inreplace.rbi
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								Library/Homebrew/utils/inreplace.rbi
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
# typed: strict
 | 
			
		||||
 | 
			
		||||
module Utils
 | 
			
		||||
  module Inreplace
 | 
			
		||||
    include Kernel
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user