ruby - How to rewrite file content with inline Guard (gem), avoiding infinite loop -
how can avoid infinite loop kind of code? (rubocop's auto-correct re-write files, although system
command think)
require 'guard/compat/plugin' module ::guard class rubyhtmlsyntaxfixer < plugin def run_on_modifications(paths) paths.each |path| text = file.read(path) text.gsub!('replace text', 'with cool') file.open(path, 'w') {|file| file.puts text } end end end end guard 'ruby_html_syntax_fixer' watch(%r{app/views/.+\.(erb|haml|slim)}) end
Comments
Post a Comment