blob: a6451c49f0256ba8168371f0b6b969862ccf5f25 (
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
|
module Utils
module Inreplace
def inreplace paths, before=nil, after=nil
Array(paths).each do |path|
s = File.open(path, "rb", &:read)
if before.nil? && after.nil?
yield s.extend(StringInreplaceExtension)
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
Pathname(path).atomic_write(s)
end
end
end
end
|