Module FileUtils
In: lib/rake.rb

This a FileUtils extension that defines several additional commands to be added to the FileUtils utility functions.

Methods

ruby   safe_ln   sh   split_all  

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}

[Source]

     # File lib/rake.rb, line 746
746:   def ruby(*args,&block)
747:     options = (Hash === args.last) ? args.pop : {}
748:     if args.length > 1 then
749:       sh(*([RUBY] + args + [options]), &block)
750:     else
751:       sh("#{RUBY} #{args}", options, &block)
752:     end
753:   end

Attempt to do a normal file link, but fall back to a copy if the link fails.

[Source]

     # File lib/rake.rb, line 759
759:   def safe_ln(*args)
760:     unless LN_SUPPORTED[0]
761:       cp(*args)
762:     else
763:       begin
764:         ln(*args)
765:       rescue StandardError, NotImplementedError => ex
766:         LN_SUPPORTED[0] = false
767:         cp(*args)
768:       end
769:     end
770:   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

[Source]

     # File lib/rake.rb, line 724
724:   def sh(*cmd, &block)
725:     options = (Hash === cmd.last) ? cmd.pop : {}
726:     unless block_given?
727:       show_command = cmd.join(" ")
728:       show_command = show_command[0,42] + "..." if show_command.length > 45
729:       block = lambda { |ok, status|
730:         ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
731:       }
732:     end
733:     rake_check_options options, :noop, :verbose
734:     rake_output_message cmd.join(" ") if options[:verbose]
735:     unless options[:noop]
736:       res = system(*cmd)
737:       block.call(res, $?)
738:     end
739:   end

Split a file path into individual directory names.

Example:

  split_all("a/b/c") =>  ['a', 'b', 'c']

[Source]

     # File lib/rake.rb, line 777
777:   def split_all(path)
778:     head, tail = File.split(path)
779:     return [tail] if head == '.' || tail == '/'
780:     return [head, tail] if head == '/'
781:     return split_all(head) + [tail]
782:   end

[Validate]