module FileUtils
########################################################################### This a FileUtils
extension that defines several additional commands to be added to the FileUtils
utility functions.
Constants
- LN_SUPPORTED
- RUBY
-
Path to the currently running Ruby program
Public Instance Methods
Source
# File lib/rake/file_utils.rb 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
Run a Ruby interpreter with the given arguments.
Example:
ruby %{-pe '$_.upcase!' <README}
Source
# File lib/rake/file_utils.rb 88 def safe_ln(*args) 89 unless LN_SUPPORTED[0] 90 cp(*args) 91 else 92 begin 93 ln(*args) 94 rescue StandardError, NotImplementedError 95 LN_SUPPORTED[0] = false 96 cp(*args) 97 end 98 end 99 end
Attempt to do a normal file link, but fall back to a copy if the link fails.
Source
# File lib/rake/file_utils.rb 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
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/file_utils.rb 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
Split a file path into individual directory names.
Example:
split_all("a/b/c") => ['a', 'b', 'c']
Private Instance Methods
Source
# File lib/rake/file_utils.rb 49 def create_shell_runner(cmd) 50 show_command = cmd.join(" ") 51 show_command = show_command[0,42] + "..." unless $trace 52 lambda { |ok, status| 53 ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]" 54 } 55 end
Source
# File lib/rake/file_utils.rb 65 def rake_system(*cmd) 66 Rake::AltSystem.system(*cmd) 67 end
Source
# File lib/rake/file_utils.rb 58 def set_verbose_option(options) 59 if options[:verbose].nil? 60 options[:verbose] = Rake::FileUtilsExt.verbose_flag.nil? || Rake::FileUtilsExt.verbose_flag 61 end 62 end