Sha256: f1cdce754de22eba425d3d425b1ed35218e92c7e9aa432187c95951f427a400c
Contents?: true
Size: 549 Bytes
Versions: 2
Compression:
Stored size: 549 Bytes
Contents
module PrLog # Injects text into a file class Injector pattr_initialize :destination_file def insert_after(line, text) unless replace!(/#{line}/, '\0' + text) raise(InsertPointNotFound, "Insert point not found in #{destination_file}.") end end private 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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pr_log-0.3.0 | lib/pr_log/injector.rb |
pr_log-0.2.0 | lib/pr_log/injector.rb |