aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorAdam Vandenberg2012-02-12 10:36:16 -0800
committerAdam Vandenberg2012-02-12 20:08:56 -0800
commit9ee5e14e6de2d849e737a3cee20784daef48f3fe (patch)
treeb57aedcd48cf1332b47b0e9ef63221982cbbdb49 /Library/Homebrew
parent10ddeaef8b8d19bcffed989d863cda6dc81c90dc (diff)
downloadbrew-9ee5e14e6de2d849e737a3cee20784daef48f3fe.tar.bz2
Pathname.install_symlink
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/extend/pathname.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb
index 2661ab5a3..d1b043097 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?