Class: Pathname

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

Overview

Some handy additions to the Pathname class. Why aren't they there already?

Instance Method Summary collapse

Instance Method Details

#jss_append(content) ⇒ Object

Append some string content to a file.

Simpler than always using an open('a') block


63
64
65
# File 'lib/jss/ruby_extensions/pathname.rb', line 63

def jss_append(content)
  self.open('a'){|f| f.write content.to_s}
end

#jss_chown(u, g) ⇒ Object

Pathname should use FileUtils.chown, not File.chown


75
76
77
# File 'lib/jss/ruby_extensions/pathname.rb', line 75

def jss_chown(u,g)
  FileUtils.chown u, g, @path
end

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

Copy a path to a destination

See Also:

  • FileUtils.cp

40
41
42
# File 'lib/jss/ruby_extensions/pathname.rb', line 40

def jss_cp(dest, options = {})
  FileUtils.cp @path, dest.to_s, options
end

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

Recursively copy this path to a destination

See Also:

  • FileUtils.cp_r

46
47
48
# File 'lib/jss/ruby_extensions/pathname.rb', line 46

def jss_cp_r(dest, options = {})
  FileUtils.cp_r @path, dest.to_s, options
end

#jss_real_file?Boolean

Is this a real file rather than a symlink?

See Also:

  • FileTest.real_file

34
35
36
# File 'lib/jss/ruby_extensions/pathname.rb', line 34

def jss_real_file?
  FileTest.jss_real_file? self 
end

#jss_save(content) ⇒ Object

Write some string content to a file.

Simpler than always using an open('w') block CAUTION this overwrites files!


55
56
57
# File 'lib/jss/ruby_extensions/pathname.rb', line 55

def jss_save(content)
  self.open('w'){|f| f.write content.to_s}
end

#jss_touchObject

Touching can be good

See Also:

  • FileUtils.touch

70
71
72
# File 'lib/jss/ruby_extensions/pathname.rb', line 70

def jss_touch
  FileUtils.touch @path
end