Method: Object#rm_r
- Defined in:
- lib/mspec/helpers/fs.rb
#rm_r(*paths) ⇒ Object
Recursively removes all files and directories in path if path is a directory. Removes the file if path is a file.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mspec/helpers/fs.rb', line 31 def rm_r(*paths) paths.each do |path| path = File. path prefix = SPEC_TEMP_DIR unless path[0, prefix.size] == prefix raise ArgumentError, "#{path} is not prefixed by #{prefix}" end # File.symlink? needs to be checked first as # File.exist? returns false for dangling symlinks if File.symlink? path File.unlink path elsif File.directory? path Dir.entries(path).each { |x| rm_r "#{path}/#{x}" unless x =~ /^\.\.?$/ } Dir.rmdir path elsif File.exist? path File.delete path end end end |