2025-07-31 17:31:27 +01:00
|
|
|
# typed: strict
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-08-17 18:42:42 +02:00
|
|
|
# Helper module for installing default files.
|
2013-10-06 22:04:46 +01:00
|
|
|
module InstallRenamed
|
2025-07-31 17:31:27 +01:00
|
|
|
sig {
|
|
|
|
params(src: T.any(String, Pathname), new_basename: String,
|
|
|
|
_block: T.nilable(T.proc.params(src: Pathname, dst: Pathname).returns(T.nilable(Pathname)))).void
|
|
|
|
}
|
|
|
|
def install_p(src, new_basename, &_block)
|
2013-10-06 22:04:46 +01:00
|
|
|
super do |src, dst|
|
2015-03-26 22:22:45 -04:00
|
|
|
if src.directory?
|
2016-03-07 15:11:00 +00:00
|
|
|
dst.install(src.children)
|
|
|
|
next
|
2015-03-26 22:22:45 -04:00
|
|
|
else
|
|
|
|
append_default_if_different(src, dst)
|
2014-08-25 10:28:40 +01:00
|
|
|
end
|
2013-10-06 22:04:46 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2025-07-31 17:31:27 +01:00
|
|
|
sig {
|
|
|
|
params(pattern: T.any(Pathname, String, Regexp), replacement: T.any(Pathname, String),
|
|
|
|
_block: T.nilable(T.proc.params(src: Pathname, dst: Pathname).returns(Pathname))).void
|
|
|
|
}
|
|
|
|
def cp_path_sub(pattern, replacement, &_block)
|
2013-10-05 20:29:02 +01:00
|
|
|
super do |src, dst|
|
|
|
|
append_default_if_different(src, dst)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2025-07-31 17:31:27 +01:00
|
|
|
sig { params(other: T.any(String, Pathname)).returns(Pathname) }
|
2017-09-24 20:12:58 +01:00
|
|
|
def +(other)
|
2024-05-23 17:08:41 +01:00
|
|
|
super.extend(InstallRenamed)
|
2014-08-25 10:28:40 +01:00
|
|
|
end
|
|
|
|
|
2025-07-31 17:31:27 +01:00
|
|
|
sig { params(other: T.any(String, Pathname)).returns(Pathname) }
|
2017-09-24 20:12:58 +01:00
|
|
|
def /(other)
|
2024-05-23 17:08:41 +01:00
|
|
|
super.extend(InstallRenamed)
|
2014-08-25 10:28:40 +01:00
|
|
|
end
|
|
|
|
|
2013-10-06 22:04:46 +01:00
|
|
|
private
|
|
|
|
|
2025-07-31 17:31:27 +01:00
|
|
|
sig { params(src: Pathname, dst: Pathname).returns(Pathname) }
|
2015-03-26 22:22:45 -04:00
|
|
|
def append_default_if_different(src, dst)
|
|
|
|
if dst.file? && !FileUtils.identical?(src, dst)
|
|
|
|
Pathname.new("#{dst}.default")
|
|
|
|
else
|
|
|
|
dst
|
2013-10-06 22:04:46 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|