diff options
| author | Adam Vandenberg | 2012-02-12 10:36:16 -0800 |
|---|---|---|
| committer | Adam Vandenberg | 2012-02-12 20:08:56 -0800 |
| commit | 3cd5c902ae28a20e13474d07914b65ebafea9c03 (patch) | |
| tree | 9e9c26c7ec6bacc6a7f9d9f4cd3479d217db5f2e /Library | |
| parent | ef22479b99013cd54530c0128f2e3758bc16d0af (diff) | |
| download | homebrew-3cd5c902ae28a20e13474d07914b65ebafea9c03.tar.bz2 | |
Pathname.install_symlink
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/extend/pathname.rb | 30 |
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? |
