From c8e79c3309d79b95ccdf166574485e638522c8db Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Thu, 11 Jul 2013 21:55:02 -0500 Subject: Move inreplace off of Object Closes Homebrew/homebrew#21163. --- Library/Homebrew/utils/inreplace.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Library/Homebrew/utils/inreplace.rb (limited to 'Library/Homebrew/utils') diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb new file mode 100644 index 000000000..4b3cf9587 --- /dev/null +++ b/Library/Homebrew/utils/inreplace.rb @@ -0,0 +1,24 @@ +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 -- cgit v1.2.3