blob: 4fa2fbe7c25c1a4a4bb92a9307087e0314c1160e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
module Utils
module Inreplace
def inreplace paths, before=nil, after=nil
Array(paths).each do |path|
f = File.open(path, 'rb')
s = f.read
if before.nil? && after.nil?
s.extend(StringInreplaceExtension)
yield s
else
after = after.to_s if Symbol === after
unless s.gsub!(before, after)
message = <<-EOS.undent
inreplace in '#{path}' failed
Expected replacement of '#{before}' with '#{after}'
EOS
ARGV.homebrew_developer? ? odie(message) : opoo(message)
end
end
f.reopen(path, 'wb').write(s)
f.close
end
end
end
end
|