class PrLog::Injector
Injects text into a file
Public Instance Methods
insert_after(line, text)
click to toggle source
# File lib/pr_log/injector.rb, line 6 def insert_after(line, text) unless replace!(/#{line}/, '\0' + text) raise(InsertPointNotFound, "Insert point not found in #{destination_file}.") end end
Private Instance Methods
replace!(regexp, text)
click to toggle source
# File lib/pr_log/injector.rb, line 15 def replace!(regexp, text) content = File.binread(destination_file) return false unless content.gsub!(regexp, text) File.open(destination_file, 'wb') do |file| file.write(content) end end