########################################################################### This a FileUtils extension that defines several additional commands to be added to the FileUtils utility functions.
Path to the currently running Ruby program
Run a Ruby interpreter with the given arguments.
Example:
ruby %{-pe '$_.upcase!' <README}
# File lib/rake/file_utils.rb, line 75 75: def ruby(*args,&block) 76: options = (Hash === args.last) ? args.pop : {} 77: if args.length > 1 then 78: sh(*([RUBY] + args + [options]), &block) 79: else 80: sh("#{RUBY} #{args.first}", options, &block) 81: end 82: end
Attempt to do a normal file link, but fall back to a copy if the link fails.
# File lib/rake/file_utils.rb, line 88 88: def safe_ln(*args) 89: unless LN_SUPPORTED[0] 90: cp(*args) 91: else 92: begin 93: ln(*args) 94: rescue StandardError, NotImplementedError => ex 95: LN_SUPPORTED[0] = false 96: cp(*args) 97: end 98: end 99: 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
# File lib/rake/file_utils.rb, line 34 34: def sh(*cmd, &block) 35: options = (Hash === cmd.last) ? cmd.pop : {} 36: shell_runner = block_given? ? block : create_shell_runner(cmd) 37: set_verbose_option(options) 38: options[:noop] ||= Rake::FileUtilsExt.nowrite_flag 39: Rake.rake_check_options options, :noop, :verbose 40: Rake.rake_output_message cmd.join(" ") if options[:verbose] 41: unless options[:noop] 42: res = rake_system(*cmd) 43: status = $? 44: status = PseudoStatus.new(1) if !res && status.nil? 45: shell_runner.call(res, status) 46: end 47: end
Split a file path into individual directory names.
Example:
split_all("a/b/c") => ['a', 'b', 'c']
# File lib/rake/file_utils.rb, line 106 106: def split_all(path) 107: head, tail = File.split(path) 108: return [tail] if head == '.' || tail == '/' 109: return [head, tail] if head == '/' 110: return split_all(head) + [tail] 111: end
# File lib/rake/file_utils.rb, line 49 49: def create_shell_runner(cmd) 50: show_command = cmd.join(" ") 51: show_command = show_command[0,42] + "..." unless $trace 52: block = lambda { |ok, status| 53: ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]" 54: } 55: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.