How to rewrite file content with inline Guard, avoiding infinite loop

12 views
Skip to first unread message

fre...@frexuz.com

unread,
Sep 10, 2016, 6:56:27 AM9/10/16
to guard-dev
How can I avoid an infinite loop with this kind of code?
(Rubocop's auto-correct does re-write files, although with a `system` command I think)

require 'guard/compat/plugin'


module ::Guard
 
class RubyHtmlSyntaxFixer < Plugin
   
def run_on_modifications(paths)
      paths
.each do |path|
        text
= File.read(path)
        text
.gsub!('replace text', 'with something cool')
       
File.open(path, 'w') {|file| file.puts text }
     
end
   
end
 
end
end


guard
'ruby_html_syntax_fixer' do
  watch
(%r{app/views/.+\.(erb|haml|slim)})
end


Reply all
Reply to author
Forward
0 new messages