This a FileUtils extension that defines several additional commands to be added to the FileUtils utility functions.
Methods
Constants
| RUBY_EXT | = | ((Config::CONFIG['ruby_install_name'] =~ /\.(com|cmd|exe|bat|rb|sh)$/) ? "" : Config::CONFIG['EXEEXT']) |
| RUBY | = | File.join( Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'] + RUBY_EXT). sub(/.*\s.*/m, '"\&"') |
| 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 1024
1024: def ruby(*args,&block)
1025: options = (Hash === args.last) ? args.pop : {}
1026: if args.length > 1 then
1027: sh(*([RUBY] + args + [options]), &block)
1028: else
1029: sh("#{RUBY} #{args.first}", options, &block)
1030: end
1031: 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 1037
1037: def safe_ln(*args)
1038: unless LN_SUPPORTED[0]
1039: cp(*args)
1040: else
1041: begin
1042: ln(*args)
1043: rescue StandardError, NotImplementedError => ex
1044: LN_SUPPORTED[0] = false
1045: cp(*args)
1046: end
1047: end
1048: 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 988
988: def sh(*cmd, &block)
989: options = (Hash === cmd.last) ? cmd.pop : {}
990: unless block_given?
991: show_command = cmd.join(" ")
992: show_command = show_command[0,42] + "..." unless $trace
993: # TODO code application logic heref show_command.length > 45
994: block = lambda { |ok, status|
995: ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
996: }
997: end
998: if RakeFileUtils.verbose_flag == :default
999: options[:verbose] = true
1000: else
1001: options[:verbose] ||= RakeFileUtils.verbose_flag
1002: end
1003: options[:noop] ||= RakeFileUtils.nowrite_flag
1004: rake_check_options options, :noop, :verbose
1005: rake_output_message cmd.join(" ") if options[:verbose]
1006: unless options[:noop]
1007: res = rake_system(*cmd)
1008: status = $?
1009: status = PseudoStatus.new(1) if !res && status.nil?
1010: block.call(res, status)
1011: end
1012: 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 1055
1055: def split_all(path)
1056: head, tail = File.split(path)
1057: return [tail] if head == '.' || tail == '/'
1058: return [head, tail] if head == '/'
1059: return split_all(head) + [tail]
1060: end