Merge pull request #15800 from dduugg/inreplace-paths
Narrow member type of inreplace paths enumerable
This commit is contained in:
commit
799417343a
@ -2556,7 +2556,7 @@ class Formula
|
|||||||
# @api public
|
# @api public
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
paths: T.any(T::Enumerable[T.untyped], String, Pathname),
|
paths: T.any(T::Enumerable[T.any(String, Pathname)], String, Pathname),
|
||||||
before: T.nilable(T.any(Pathname, Regexp, String)),
|
before: T.nilable(T.any(Pathname, Regexp, String)),
|
||||||
after: T.nilable(T.any(Pathname, String, Symbol)),
|
after: T.nilable(T.any(Pathname, String, Symbol)),
|
||||||
audit_result: T::Boolean,
|
audit_result: T::Boolean,
|
||||||
|
|||||||
@ -39,21 +39,22 @@ module Utils
|
|||||||
# @api public
|
# @api public
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
paths: T.any(T::Array[T.untyped], String, Pathname),
|
paths: T.any(T::Enumerable[T.any(String, Pathname)], String, Pathname),
|
||||||
before: T.nilable(T.any(Pathname, Regexp, String)),
|
before: T.nilable(T.any(Pathname, Regexp, String)),
|
||||||
after: T.nilable(T.any(Pathname, String, Symbol)),
|
after: T.nilable(T.any(Pathname, String, Symbol)),
|
||||||
audit_result: T::Boolean,
|
audit_result: T::Boolean,
|
||||||
).void
|
).void
|
||||||
}
|
}
|
||||||
def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
|
def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
|
||||||
|
paths = Array(paths)
|
||||||
after &&= after.to_s
|
after &&= after.to_s
|
||||||
before = before.to_s if before.is_a?(Pathname)
|
before = before.to_s if before.is_a?(Pathname)
|
||||||
|
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
errors["`paths` (first) parameter"] = ["`paths` was empty"] if paths.blank?
|
errors["`paths` (first) parameter"] = ["`paths` was empty"] if paths.all?(&:blank?)
|
||||||
|
|
||||||
Array(paths).each do |path|
|
paths.each do |path|
|
||||||
str = File.binread(path)
|
str = File.binread(path)
|
||||||
s = StringInreplaceExtension.new(str)
|
s = StringInreplaceExtension.new(str)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user