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']). sub(/.*\s.*/m, '"\&"')
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 1000
1000:   def ruby(*args,&block)
1001:     options = (Hash === args.last) ? args.pop : {}
1002:     if args.length > 1 then
1003:       sh(*([RUBY] + args + [options]), &block)
1004:     else
1005:       sh("#{RUBY} #{args.first}", options, &block)
1006:     end
1007:   end

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

[Source]

      # File lib/rake.rb, line 1013
1013:   def safe_ln(*args)
1014:     unless LN_SUPPORTED[0]
1015:       cp(*args)
1016:     else
1017:       begin
1018:         ln(*args)
1019:       rescue StandardError, NotImplementedError => ex
1020:         LN_SUPPORTED[0] = false
1021:         cp(*args)
1022:       end
1023:     end
1024:   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 962
962:   def sh(*cmd, &block)
963:     options = (Hash === cmd.last) ? cmd.pop : {}
964:     unless block_given?
965:       show_command = cmd.join(" ")
966:       show_command = show_command[0,42] + "..."
967:       # TODO code application logic heref show_command.length > 45
968:       block = lambda { |ok, status|
969:         ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
970:       }
971:     end
972:     if RakeFileUtils.verbose_flag == :default
973:       options[:verbose] = true
974:     else
975:       options[:verbose] ||= RakeFileUtils.verbose_flag
976:     end
977:     options[:noop]    ||= RakeFileUtils.nowrite_flag
978:     rake_check_options options, :noop, :verbose
979:     rake_output_message cmd.join(" ") if options[:verbose]
980:     unless options[:noop]
981:       res = rake_system(*cmd)
982:       block.call(res, $?)
983:     end
984:   end

Split a file path into individual directory names.

Example:

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

[Source]

      # File lib/rake.rb, line 1031
1031:   def split_all(path)
1032:     head, tail = File.split(path)
1033:     return [tail] if head == '.' || tail == '/'
1034:     return [head, tail] if head == '/'
1035:     return split_all(head) + [tail]
1036:   end

[Validate]