Skip to content

Ability to have gsub_file error if it didn't gsub anything #874

@G-Rath

Description

@G-Rath

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!?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions