Class: Pathname

Inherits:
Object show all
Defined in:
lib/quality_extensions/pathname.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.tempfileObject

Creates a new temp file using Tempfile.new and returns the Pathname object for that file



16
17
18
# File 'lib/quality_extensions/pathname.rb', line 16

def self.tempfile
  Pathname.new(Tempfile.new('Pathname').path)
end

Instance Method Details

#cp(new_path, options = {}) ⇒ Object Also known as: copy

Copies self to new_path using FileUtils.cp.

See documentation for FileUtils.cp for a list of valid options.

Returns Pathname object for new_file file.



38
39
40
41
# File 'lib/quality_extensions/pathname.rb', line 38

def cp(new_path, options = {})
  FileUtils.cp self.to_s, new_path.to_s, options
  Pathname.new(new_path)
end

#install(dest, options = {}) ⇒ Object

Copies/install self to dest using FileUtils.install.

If src is not same as dest, copies it and changes the permission mode to mode. If dest is a directory, destination is dest/src.

FileUtils.install 'ruby', '/usr/local/bin/ruby', :mode => 0755, :verbose => true
FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', :verbose => true

Returns Pathname object for dest file.



54
55
56
57
# File 'lib/quality_extensions/pathname.rb', line 54

def install(dest, options = {})
  FileUtils.install self.to_s, dest.to_s, options
  Pathname.new(dest)
end

#mv(new_path, options = {}) ⇒ Object Also known as: move

Moves self to new_path using FileUtils.mv.

See documentation for FileUtils.mv for a list of valid options.

Returns Pathname object for new_file file.



26
27
28
29
# File 'lib/quality_extensions/pathname.rb', line 26

def mv(new_path, options = {})
  FileUtils.mv self.to_s, new_path.to_s, options
  Pathname.new(new_path)
end