lib/line_containing.rb in line_containing-0.1.0 vs lib/line_containing.rb in line_containing-0.1.1
- old
+ new
@@ -1,11 +1,10 @@
require 'line_containing/version'
#
module LineContaining
def self.add_before(str_orig, str_add, path)
- system('pwd')
path_old = path
path_new = "#{path_old}.new"
file_w = open(path_new, 'w')
File.readlines(path_old).each do |line|
file_w.write("#{str_add}\n") if line.include? str_orig
@@ -19,15 +18,13 @@
def self.add_after(str_orig, str_add, path)
path_old = path
path_new = "#{path_old}.new"
file_w = open(path_new, 'w')
File.readlines(path_old).each do |line|
+ file_w.write(line)
if line.include? str_orig
- file_w.write(line)
file_w.write("\n") if line[-1] != "\n"
file_w.write("#{str_add}\n")
- else
- file_w.write(line)
end
end
file_w.close
system("rm #{path_old}")
system("mv #{path_new} #{path_old}")