lib/pineapples/actions/gsub_file.rb in pineapples-0.3.34 vs lib/pineapples/actions/gsub_file.rb in pineapples-0.3.345
- old
+ new
@@ -21,16 +21,18 @@
options = args.last.is_a?(Hash) ? args.pop : {}
verbose = options.fetch(:verbose, verbose?)
execute = options.fetch(:pretend, execute?)
- path = File.expand_path(path, app_root)
+ fullpath = File.expand_path(path, app_root)
+ raise Error, "File #{path} doesn't exist!" if !File.exist?(fullpath)
+
say_status :gsub, relative_to_app_root(path), :light_yellow, verbose
if execute
- content = File.binread(path)
+ content = File.binread(fullpath)
content.gsub!(flag, *args, &block)
- File.open(path, 'wb') { |file| file.write(content) }
+ File.open(fullpath, 'wb') { |file| file.write(content) }
end
end
end
end