123456789_123456789_123456789_123456789_123456789_

Class: Pathname

Relationships & Source Files
Inherits: Object
Defined in: lib/pathname.rb,
lib/pathname.rb,
lib/pathname.rb

Overview

pathname.rb

Object-Oriented Pathname Class

Author

Tanaka Akira <akr@m17n.org>

Documentation

Author and Gavin Sinclair

For documentation, see class Pathname.

Class Method Summary

  • .mktmpdir

    Creates a tmp directory and wraps the returned path in a Pathname object.

Instance Method Summary

Class Method Details

.mktmpdir

Creates a tmp directory and wraps the returned path in a Pathname object.

Note that you need to require ‘pathname’ to use this method.

See Dir.mktmpdir

[ GitHub ]

  
# File 'lib/pathname.rb', line 63

def self.mktmpdir
  require 'tmpdir' unless defined?(Dir.mktmpdir)
  if block_given?
    Dir.mktmpdir do |dir|
      dir = self.new(dir)
      yield dir
    end
  else
    self.new(Dir.mktmpdir)
  end
end

Instance Method Details

#find(ignore_error: true)

Iterates over the directory tree in a depth first manner, yielding a Pathname for each file under “this” directory.

Note that you need to require ‘pathname’ to use this method.

Returns an Enumerator if no block is given.

Since it is implemented by the standard library module Find, Find.prune can be used to control the traversal.

If self is ., yielded pathnames begin with a filename in the current directory, not ./.

See Find.find

[ GitHub ]

  
# File 'lib/pathname.rb', line 30

def find(ignore_error: true) # :yield: pathname
  return to_enum(__method__, ignore_error: ignore_error) unless block_given?
  require 'find'
  if @path == '.'
    Find.find(@path, ignore_error: ignore_error) {|f| yield self.class.new(f.delete_prefix('./')) }
  else
    Find.find(@path, ignore_error: ignore_error) {|f| yield self.class.new(f) }
  end
end

#rmtree(noop: nil, verbose: nil, secure: nil)

Recursively deletes a directory, including all directories beneath it.

Note that you need to require ‘pathname’ to use this method.

See FileUtils.rm_rf

[ GitHub ]

  
# File 'lib/pathname.rb', line 48

def rmtree(noop: nil, verbose: nil, secure: nil)
  # The name "rmtree" is borrowed from File::Path of Perl.
  # File::Path provides "mkpath" and "rmtree".
  require 'fileutils'
  FileUtils.rm_rf(@path, noop: noop, verbose: verbose, secure: secure)
  self
end