You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!?
The text was updated successfully, but these errors were encountered:
…o longer doing anything (#533)
So it turns out that `gsub_file` does not actually check if it matched
anything and so we have a few misc. changes silently not being applied
due to changes in Rails 7.1.
This addresses that by switching us to use `gsub_file!` which reads the
file into memory before it's gsub'd and then compares the results to
make sure it actually changed.
I've opened rails/thor#874 to add this to Thor
itself
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!
?The text was updated successfully, but these errors were encountered: