Class: Pathname

Inherits:
Object
  • Object
show all
Defined in:
lib/jss-api/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



62
63
64
# File 'lib/jss-api/ruby_extensions/pathname.rb', line 62

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



74
75
76
# File 'lib/jss-api/ruby_extensions/pathname.rb', line 74

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


39
40
41
# File 'lib/jss-api/ruby_extensions/pathname.rb', line 39

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


45
46
47
# File 'lib/jss-api/ruby_extensions/pathname.rb', line 45

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?

Returns:

  • (Boolean)

See Also:

  • FileTest.real_file


33
34
35
# File 'lib/jss-api/ruby_extensions/pathname.rb', line 33

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!



54
55
56
# File 'lib/jss-api/ruby_extensions/pathname.rb', line 54

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

#jss_touchObject

Touching can be good

See Also:

  • FileUtils.touch


69
70
71
# File 'lib/jss-api/ruby_extensions/pathname.rb', line 69

def jss_touch
  FileUtils.touch @path
end