Merge pull request #15807 from dduugg/static-inreplace
Make `inreplace` a purely static method
This commit is contained in:
commit
3ced9156da
@ -6,8 +6,6 @@ require "utils/inreplace"
|
|||||||
|
|
||||||
module Cask
|
module Cask
|
||||||
class Migrator
|
class Migrator
|
||||||
extend ::Utils::Inreplace
|
|
||||||
|
|
||||||
attr_reader :old_cask, :new_cask
|
attr_reader :old_cask, :new_cask
|
||||||
|
|
||||||
sig { params(old_cask: Cask, new_cask: Cask).void }
|
sig { params(old_cask: Cask, new_cask: Cask).void }
|
||||||
@ -74,7 +72,7 @@ module Cask
|
|||||||
def self.replace_caskfile_token(path, old_token, new_token)
|
def self.replace_caskfile_token(path, old_token, new_token)
|
||||||
case path.extname
|
case path.extname
|
||||||
when ".rb"
|
when ".rb"
|
||||||
inreplace path, /\A\s*cask\s+"#{Regexp.escape(old_token)}"/, "cask #{new_token.inspect}"
|
::Utils::Inreplace.inreplace path, /\A\s*cask\s+"#{Regexp.escape(old_token)}"/, "cask #{new_token.inspect}"
|
||||||
when ".json"
|
when ".json"
|
||||||
json = JSON.parse(path.read)
|
json = JSON.parse(path.read)
|
||||||
json["token"] = new_token
|
json["token"] = new_token
|
||||||
|
|||||||
@ -59,7 +59,6 @@ require "extend/api_hashable"
|
|||||||
# end</pre>
|
# end</pre>
|
||||||
class Formula
|
class Formula
|
||||||
include FileUtils
|
include FileUtils
|
||||||
include Utils::Inreplace
|
|
||||||
include Utils::Shebang
|
include Utils::Shebang
|
||||||
include Utils::Shell
|
include Utils::Shell
|
||||||
include Context
|
include Context
|
||||||
@ -2563,7 +2562,7 @@ class Formula
|
|||||||
).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
|
||||||
super(paths, before, after, audit_result)
|
Utils::Inreplace.inreplace(paths, before, after, audit_result: audit_result)
|
||||||
rescue Utils::Inreplace::Error => e
|
rescue Utils::Inreplace::Error => e
|
||||||
onoe e.to_s
|
onoe e.to_s
|
||||||
raise BuildError.new(self, "inreplace", Array(paths), {})
|
raise BuildError.new(self, "inreplace", Array(paths), {})
|
||||||
|
|||||||
@ -18,8 +18,6 @@ module Utils
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
# Sometimes we have to change a bit before we install. Mostly we
|
# Sometimes we have to change a bit before we install. Mostly we
|
||||||
# prefer a patch, but if you need the {Formula#prefix prefix} of
|
# prefer a patch, but if you need the {Formula#prefix prefix} of
|
||||||
# this formula in the patch you have to resort to `inreplace`,
|
# this formula in the patch you have to resort to `inreplace`,
|
||||||
@ -45,7 +43,7 @@ module Utils
|
|||||||
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 self.inreplace(paths, before = nil, after = nil, audit_result: true)
|
||||||
paths = Array(paths)
|
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)
|
||||||
@ -73,7 +71,7 @@ module Utils
|
|||||||
end
|
end
|
||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
def inreplace_pairs(path, replacement_pairs, read_only_run: false, silent: false)
|
def self.inreplace_pairs(path, replacement_pairs, read_only_run: false, silent: false)
|
||||||
str = File.binread(path)
|
str = File.binread(path)
|
||||||
contents = StringInreplaceExtension.new(str)
|
contents = StringInreplaceExtension.new(str)
|
||||||
replacement_pairs.each do |old, new|
|
replacement_pairs.each do |old, new|
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Utils
|
|
||||||
module Inreplace
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Loading…
x
Reference in New Issue
Block a user