Sha256: 8b76dd20a111ec5944906e1209494958fa9c8958966e2ac6e2d120f2fc700d79
Contents?: true
Size: 1007 Bytes
Versions: 1
Compression:
Stored size: 1007 Bytes
Contents
module TextFileMutator def self.insert_before(file, line, txt_before) gsub_file file, /(#{Regexp.escape(line)})/mi do |match| "#{txt_before}\n#{match}" end end def self.insert_after(file, line, txt_after) gsub_file file, /(#{Regexp.escape(line)})/mi do |match| "#{match}\n#{txt_after}" end end def self.comment_gem_config(file, line) gsub_file file, /^#?(config.gem.+'#{Regexp.escape(line)}'.+)/mi do |match| "# " + "#{match}" end end def self.comment_line(file, line) puts "comment line: #{line}" gsub_file file, /^#?(#{Regexp.escape(line)})/mi do |match| puts "match: #{match}" "# " + "#{match}" end end def self.remove_line(file, line) gsub_file file, /(#{Regexp.escape(line)})/mi do |match| "" end end protected def self.gsub_file(path, regexp, *args, &block) content = File.read(path).gsub(regexp, *args, &block) File.open(path, 'wb') { |file| file.write(content) } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
txt_file_mutator-0.1.0 | lib/txt_file_mutator.rb |