I recently discovered that gsub_file does not error when it does not match; this feels like a bit of a footgun to me.
I've worked around this using this utility function to ensure the file contents has changed:
def gsub_file!(path, flag, *args, &block)
content = File.binread(path)
gsub_file(path, flag, *args, &block)
raise StandardError, "the contents of #{path} did not change!" if content == File.binread(path)
end
However, I think it would be a good addition to thor itself - I'm thinking maybe gsub_file "", "", "", error_on_no_change: true and then an alias of gsub_file!?
I recently discovered that
gsub_file
does not error when it does not match; this feels like a bit of a footgun to me.I've worked around this using this utility function to ensure the file contents has changed:
However, I think it would be a good addition to
thor
itself - I'm thinking maybegsub_file "", "", "", error_on_no_change: true
and then an alias ofgsub_file!
?