aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils
diff options
context:
space:
mode:
authorJack Nagel2013-07-11 21:55:02 -0500
committerJack Nagel2013-07-12 16:23:06 -0500
commitc8e79c3309d79b95ccdf166574485e638522c8db (patch)
tree20a0059edf4522853badf13e5a0979102b8f53b9 /Library/Homebrew/utils
parent6a205ab26313eb1845bdbc1c3e9af5e7041bc5d3 (diff)
downloadbrew-c8e79c3309d79b95ccdf166574485e638522c8db.tar.bz2
Move inreplace off of Object
Closes Homebrew/homebrew#21163.
Diffstat (limited to 'Library/Homebrew/utils')
-rw-r--r--Library/Homebrew/utils/inreplace.rb24
1 files changed, 24 insertions, 0 deletions
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