Support Pathname as second arg to gsub!
This commit is contained in:
parent
6d53c52d2c
commit
11bb278284
@ -57,7 +57,7 @@ describe Utils::Inreplace do
|
|||||||
it "substitutes pathname within file" 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
|
# 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|
|
described_class.inreplace(file.path) do |s|
|
||||||
s.gsub!(Pathname("b"), "f")
|
s.gsub!(Pathname("b"), Pathname("f"))
|
||||||
end
|
end
|
||||||
expect(File.binread(file)).to eq <<~EOS
|
expect(File.binread(file)).to eq <<~EOS
|
||||||
a
|
a
|
||||||
|
|||||||
@ -31,12 +31,12 @@ class StringInreplaceExtension
|
|||||||
#
|
#
|
||||||
# @api public
|
# @api public
|
||||||
sig {
|
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))
|
.returns(T.nilable(String))
|
||||||
}
|
}
|
||||||
def gsub!(before, after, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
|
def gsub!(before, after, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
|
||||||
before = before.to_s if before.is_a?(Pathname)
|
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?
|
errors << "expected replacement of #{before.inspect} with #{after.inspect}" if audit_result && result.nil?
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user