From 9ee5e14e6de2d849e737a3cee20784daef48f3fe Mon Sep 17 00:00:00 2001 From: Adam Vandenberg Date: Sun, 12 Feb 2012 10:36:16 -0800 Subject: [PATCH] Pathname.install_symlink --- Library/Homebrew/extend/pathname.rb | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 2661ab5a3a..d1b0430979 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -48,6 +48,36 @@ class Pathname return return_value end + # Creates symlinks to sources in this folder. + def install_symlink *sources + sources.each do |src| + case src + when Array + src.collect {|src| install_symlink_p(src) } + when Hash + src.collect {|src, new_basename| install_symlink_p(src, new_basename) } + else + install_symlink_p(src) + end + end + end + + def install_symlink_p src, new_basename = nil + if new_basename.nil? + dst = self+File.basename(src) + else + dst = self+File.basename(new_basename) + end + + src = src.to_s + dst = dst.to_s + + mkpath + FileUtils.ln_s src, dst + + return dst + end + # we assume this pathname object is a file obviously def write content raise "Will not overwrite #{to_s}" if exist? and not ARGV.force?