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 747
747: def ruby(*args,&block)
748: options = (Hash === args.last) ? args.pop : {}
749: if args.length > 1 then
750: sh(*([RUBY] + args + [options]), &block)
751: else
752: sh("#{RUBY} #{args}", options, &block)
753: end
754: 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 760
760: def safe_ln(*args)
761: unless LN_SUPPORTED[0]
762: cp(*args)
763: else
764: begin
765: ln(*args)
766: rescue StandardError, NotImplementedError => ex
767: LN_SUPPORTED[0] = false
768: cp(*args)
769: end
770: end
771: 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 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] + "..."
729: # TODO code application logic heref show_command.length > 45
730: block = lambda { |ok, status|
731: ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
732: }
733: end
734: rake_check_options options, :noop, :verbose
735: rake_output_message cmd.join(" ") if options[:verbose]
736: unless options[:noop]
737: res = system(*cmd)
738: block.call(res, $?)
739: end
740: 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 778
778: def split_all(path)
779: head, tail = File.split(path)
780: return [tail] if head == '.' || tail == '/'
781: return [head, tail] if head == '/'
782: return split_all(head) + [tail]
783: end