Skip to content

Commit db612c5

Browse files
[DOC] Enhanced RDoc for ::ln_s (#72)
1 parent 39772bc commit db612c5

File tree

1 file changed

+58
-14
lines changed

1 file changed

+58
-14
lines changed

lib/fileutils.rb

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -501,25 +501,69 @@ def cp_lr(src, dest, noop: nil, verbose: nil,
501501
end
502502
module_function :cp_lr
503503

504+
# Creates {symbolic links}[https://en.wikipedia.org/wiki/Symbolic_link].
504505
#
505-
# :call-seq:
506-
# FileUtils.ln_s(target, link, force: nil, noop: nil, verbose: nil)
507-
# FileUtils.ln_s(target, dir, force: nil, noop: nil, verbose: nil)
508-
# FileUtils.ln_s(targets, dir, force: nil, noop: nil, verbose: nil)
506+
# When +src+ is the path to an existing file:
507+
#
508+
# - When +dest+ is the path to a non-existent file,
509+
# creates a symbolic link at +dest+ pointing to +src+:
510+
#
511+
# FileUtils.touch('src0.txt')
512+
# File.exist?('dest0.txt') # => false
513+
# FileUtils.ln_s('src0.txt', 'dest0.txt')
514+
# File.symlink?('dest0.txt') # => true
515+
#
516+
# - When +dest+ is the path to an existing file,
517+
# creates a symbolic link at +dest+ pointing to +src+
518+
# if and only if keyword argument <tt>force: true</tt> is given
519+
# (raises an exception otherwise):
520+
#
521+
# FileUtils.touch('src1.txt')
522+
# FileUtils.touch('dest1.txt')
523+
# FileUtils.ln_s('src1.txt', 'dest1.txt', force: true)
524+
# FileTest.symlink?('dest1.txt') # => true
525+
#
526+
# FileUtils.ln_s('src1.txt', 'dest1.txt') # Raises Errno::EEXIST.
527+
#
528+
# When +dest+ is the path to a directory,
529+
# creates a symbolic link at <tt>dest/src</tt> pointing to +src+:
530+
#
531+
# FileUtils.touch('src2.txt')
532+
# FileUtils.mkdir('destdir2')
533+
# FileUtils.ln_s('src2.txt', 'destdir2')
534+
# File.symlink?('destdir2/src2.txt') # => true
535+
#
536+
# When +src+ is an array of paths to existing files and +dest+ is a directory,
537+
# for each child +child+ in +src+ creates a symbolic link <tt>dest/child</tt>
538+
# pointing to +child+:
509539
#
510-
# In the first form, creates a symbolic link +link+ which points to +target+.
511-
# If +link+ already exists, raises Errno::EEXIST.
512-
# But if the <tt>force</tt> option is set, overwrites +link+.
540+
# FileUtils.mkdir('srcdir3')
541+
# FileUtils.touch('srcdir3/src0.txt')
542+
# FileUtils.touch('srcdir3/src1.txt')
543+
# FileUtils.mkdir('destdir3')
544+
# FileUtils.ln_s(['srcdir3/src0.txt', 'srcdir3/src1.txt'], 'destdir3')
545+
# File.symlink?('destdir3/src0.txt') # => true
546+
# File.symlink?('destdir3/src1.txt') # => true
513547
#
514-
# FileUtils.ln_s '/usr/bin/ruby', '/usr/local/bin/ruby'
515-
# FileUtils.ln_s 'verylongsourcefilename.c', 'c', force: true
548+
# Keyword arguments:
549+
#
550+
# - <tt>force: true</tt> - overwrites +dest+ if it exists.
551+
# - <tt>noop: true</tt> - does not create links.
552+
# - <tt>verbose: true</tt> - prints an equivalent command:
553+
#
554+
# FileUtils.ln_s('src0.txt', 'dest0.txt', noop: true, verbose: true)
555+
# FileUtils.ln_s('src1.txt', 'destdir1', noop: true, verbose: true)
556+
# FileUtils.ln_s('src2.txt', 'dest2.txt', force: true, noop: true, verbose: true)
557+
# FileUtils.ln_s(['srcdir3/src0.txt', 'srcdir3/src1.txt'], 'destdir3', noop: true, verbose: true)
558+
#
559+
# Output:
516560
#
517-
# In the second form, creates a link +dir/target+ pointing to +target+.
518-
# In the third form, creates several symbolic links in the directory +dir+,
519-
# pointing to each item in +targets+.
520-
# If +dir+ is not a directory, raises Errno::ENOTDIR.
561+
# ln -s src0.txt dest0.txt
562+
# ln -s src1.txt destdir1
563+
# ln -sf src2.txt dest2.txt
564+
# ln -s srcdir3/src0.txt srcdir3/src1.txt destdir3
521565
#
522-
# FileUtils.ln_s Dir.glob('/bin/*.rb'), '/home/foo/bin'
566+
# FileUtils.symlink is an alias for FileUtils.ln_s.
523567
#
524568
def ln_s(src, dest, force: nil, noop: nil, verbose: nil)
525569
fu_output_message "ln -s#{force ? 'f' : ''} #{[src,dest].flatten.join ' '}" if verbose

0 commit comments

Comments
 (0)