Pass around only pathname objects

This commit is contained in:
Jack Nagel 2015-03-26 22:22:45 -04:00
parent 3721e0be6f
commit 96f7a8015f
2 changed files with 9 additions and 9 deletions

View File

@ -37,9 +37,8 @@ class Pathname
def install_p(src, new_basename) def install_p(src, new_basename)
raise Errno::ENOENT, src.to_s unless File.symlink?(src) || File.exist?(src) raise Errno::ENOENT, src.to_s unless File.symlink?(src) || File.exist?(src)
src = src.to_s src = Pathname(src)
dst = join(new_basename).to_s dst = join(new_basename)
dst = yield(src, dst) if block_given? dst = yield(src, dst) if block_given?
mkpath mkpath
@ -48,7 +47,7 @@ class Pathname
# is a symlink, and its target is moved first, FileUtils.mv will fail: # is a symlink, and its target is moved first, FileUtils.mv will fail:
# https://bugs.ruby-lang.org/issues/7707 # https://bugs.ruby-lang.org/issues/7707
# In that case, use the system "mv" command. # In that case, use the system "mv" command.
if File.symlink? src if src.symlink?
raise unless Kernel.system 'mv', src, dst raise unless Kernel.system 'mv', src, dst
else else
FileUtils.mv src, dst FileUtils.mv src, dst

View File

@ -1,7 +1,7 @@
module InstallRenamed module InstallRenamed
def install_p(_, new_basename) def install_p(_, new_basename)
super do |src, dst| super do |src, dst|
if File.directory?(src) if src.directory?
dst dst
else else
append_default_if_different(src, dst) append_default_if_different(src, dst)
@ -25,10 +25,11 @@ module InstallRenamed
private private
def append_default_if_different src, dst def append_default_if_different(src, dst)
if File.file? dst and !FileUtils.identical?(src, dst) if dst.file? && !FileUtils.identical?(src, dst)
dst += ".default" Pathname.new("#{dst}.default")
end else
dst dst
end end
end end
end