Skip to content
Snippets Groups Projects
Commit c8e79c33 authored by Jack Nagel's avatar Jack Nagel
Browse files

Move inreplace off of Object

Closes Homebrew/homebrew#21163.
parent 6a205ab2
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ require 'formulary'
class Formula
include FileUtils
include Utils::Inreplace
extend BuildEnvironmentDSL
attr_reader :name, :path, :homepage, :downloader
......
......@@ -2,6 +2,7 @@ require 'pathname'
require 'exceptions'
require 'macos'
require 'utils/json'
require 'utils/inreplace'
require 'open-uri'
class Tty
......@@ -213,27 +214,6 @@ def archs_for_command cmd
Pathname.new(cmd).archs
end
def inreplace paths, before=nil, after=nil
Array(paths).each do |path|
f = File.open(path, 'r')
s = f.read
if before.nil? && after.nil?
s.extend(StringInreplaceExtension)
yield s
else
sub = s.gsub!(before, after)
if sub.nil?
opoo "inreplace in '#{path}' failed"
puts "Expected replacement of '#{before}' with '#{after}'"
end
end
f.reopen(path, 'w').write(s)
f.close
end
end
def ignore_interrupts(opt = nil)
std_trap = trap("INT") do
puts "One sec, just cleaning up" unless opt == :quietly
......
module Utils
module Inreplace
def inreplace paths, before=nil, after=nil
Array(paths).each do |path|
f = File.open(path, 'r')
s = f.read
if before.nil? && after.nil?
s.extend(StringInreplaceExtension)
yield s
else
sub = s.gsub!(before, after)
if sub.nil?
opoo "inreplace in '#{path}' failed"
puts "Expected replacement of '#{before}' with '#{after}'"
end
end
f.reopen(path, 'w').write(s)
f.close
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment