########################################################################### This a FileUtils extension that defines several additional commands to be added to the FileUtils utility functions.
Methods
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}
[ show source ]
# File lib/rake.rb, line 915
915: def ruby(*args,&block)
916: options = (Hash === args.last) ? args.pop : {}
917: if args.length > 1 then
918: sh(*([RUBY] + args + [options]), &block)
919: else
920: sh("#{RUBY} #{args.first}", options, &block)
921: end
922: 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 928
928: def safe_ln(*args)
929: unless LN_SUPPORTED[0]
930: cp(*args)
931: else
932: begin
933: ln(*args)
934: rescue StandardError, NotImplementedError => ex
935: LN_SUPPORTED[0] = false
936: cp(*args)
937: end
938: end
939: 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 892
892: def sh(*cmd, &block)
893: options = (Hash === cmd.last) ? cmd.pop : {}
894: unless block_given?
895: show_command = cmd.join(" ")
896: show_command = show_command[0,42] + "..."
897: # TODO code application logic heref show_command.length > 45
898: block = lambda { |ok, status|
899: ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
900: }
901: end
902: rake_check_options options, :noop, :verbose
903: rake_output_message cmd.join(" ") if options[:verbose]
904: unless options[:noop]
905: res = system(*cmd)
906: block.call(res, $?)
907: end
908: 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 946
946: def split_all(path)
947: head, tail = File.split(path)
948: return [tail] if head == '.' || tail == '/'
949: return [head, tail] if head == '/'
950: return split_all(head) + [tail]
951: end