aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils/inreplace.rb
diff options
context:
space:
mode:
authorJack Nagel2013-07-11 21:55:02 -0500
committerJack Nagel2013-07-12 16:23:06 -0500
commit7c68757e99909e705fefa0ca4d3b2a48f4fd9f64 (patch)
tree3d99fc219782d6e72655c4e3ef5d8ac2c3e05837 /Library/Homebrew/utils/inreplace.rb
parent196afb43172ac9cc3a3ab452a547231c60fef2e3 (diff)
downloadhomebrew-7c68757e99909e705fefa0ca4d3b2a48f4fd9f64.tar.bz2
Move inreplace off of Object
Closes #21163.
Diffstat (limited to 'Library/Homebrew/utils/inreplace.rb')
-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