Support Pathname as second arg to gsub!

This commit is contained in:
Douglas Eichelberger 2023-07-23 21:14:21 -07:00
parent 6d53c52d2c
commit 11bb278284
2 changed files with 3 additions and 3 deletions

View File

@ -57,7 +57,7 @@ describe Utils::Inreplace do
it "substitutes pathname within file" do
# For a specific instance of this, see https://github.com/Homebrew/homebrew-core/blob/a8b0b10/Formula/loki.rb#L48
described_class.inreplace(file.path) do |s|
s.gsub!(Pathname("b"), "f")
s.gsub!(Pathname("b"), Pathname("f"))
end
expect(File.binread(file)).to eq <<~EOS
a

View File

@ -31,12 +31,12 @@ class StringInreplaceExtension
#
# @api public
sig {
params(before: T.any(Pathname, Regexp, String), after: String, audit_result: T::Boolean)
params(before: T.any(Pathname, Regexp, String), after: T.any(Pathname, String), audit_result: T::Boolean)
.returns(T.nilable(String))
}
def gsub!(before, after, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
before = before.to_s if before.is_a?(Pathname)
result = inreplace_string.gsub!(before, after)
result = inreplace_string.gsub!(before, after.to_s)
errors << "expected replacement of #{before.inspect} with #{after.inspect}" if audit_result && result.nil?
result
end