summaryrefslogtreecommitdiff
path: root/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb')
-rw-r--r--lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb b/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb
index 09ce0864f0..f52ced2bcd 100644
--- a/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb
+++ b/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb
@@ -106,12 +106,14 @@ class Bundler::Thor
# Adds the content to the file.
#
def replace!(regexp, string, force)
- return if pretend?
content = File.read(destination)
- if force || !content.include?(replacement)
+ before, after = content.split(regexp, 2)
+ snippet = (behavior == :after ? after : before).to_s
+
+ if force || !snippet.include?(replacement)
success = content.gsub!(regexp, string)
- File.open(destination, "wb") { |file| file.write(content) }
+ File.open(destination, "wb") { |file| file.write(content) } unless pretend?
success
end
end