This a FileUtils extension that defines several additional commands to be added to the FileUtils utility functions.
Methods
Constants
| RUBY | = | File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) |
| LN_SUPPORTED | = | [true] |
Public Instance methods
Run a Ruby interpreter with the given arguments.
Example:
ruby %{-pe '$_.upcase!' <README}
[ show source ]
# File lib/rake.rb, line 583
583: def ruby(*args,&block)
584: if Hash === args.last
585: options = args.pop
586: else
587: options = {}
588: end
589: if args.length > 1 then
590: sh(*([RUBY] + args + [options]), &block)
591: else
592: sh("#{RUBY} #{args}", options, &block)
593: end
594: end
Attempt to do a normal file link, but fall back to a copy if the link fails.
[ show source ]
# File lib/rake.rb, line 600
600: def safe_ln(*args)
601: unless LN_SUPPORTED[0]
602: cp(*args)
603: else
604: begin
605: ln(*args)
606: rescue Errno::EOPNOTSUPP, Errno::EXDEV
607: LN_SUPPORTED[0] = false
608: cp(*args)
609: end
610: end
611: end
Run the system command cmd. If multiple arguments are given the command is not run with the shell (same semantics as Kernel::exec and Kernel::system).
Example:
sh %{ls -ltr}
sh 'ls', 'file with spaces'
# check exit status after command runs
sh %{grep pattern file} do |ok, res|
if ! ok
puts "pattern not found (status = #{res.exitstatus})"
end
end
[ show source ]
# File lib/rake.rb, line 557
557: def sh(*cmd, &block)
558: if Hash === cmd.last then
559: options = cmd.pop
560: else
561: options = {}
562: end
563: unless block_given?
564: show_command = cmd.join(" ")
565: show_command = show_command[0,42] + "..." if show_command.length > 45
566: block = lambda { |ok, status|
567: ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
568: }
569: end
570: fu_check_options options, :noop, :verbose
571: fu_output_message cmd.join(" ") if options[:verbose]
572: unless options[:noop]
573: res = system(*cmd)
574: block.call(res, $?)
575: end
576: end
Split a file path into individual directory names.
Example:
split_all("a/b/c") => ['a', 'b', 'c']
[ show source ]
# File lib/rake.rb, line 618
618: def split_all(path)
619: head, tail = File.split(path)
620: return [tail] if head == '.' || tail == '/'
621: return [head, tail] if head == '/'
622: return split_all(head) + [tail]
623: end