Class: Pathname
- Inherits:
-
Object
- Object
- Pathname
- 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
-
#jss_append(content) ⇒ Object
Append some string content to a file.
-
#jss_chown(u, g) ⇒ Object
Pathname should use FileUtils.chown, not File.chown.
-
#jss_cp(dest, options = {}) ⇒ Object
Copy a path to a destination.
-
#jss_cp_r(dest, options = {}) ⇒ Object
Recursively copy this path to a destination.
-
#jss_real_file? ⇒ Boolean
Is this a real file rather than a symlink?.
-
#jss_save(content) ⇒ Object
Write some string content to a file.
-
#jss_touch ⇒ Object
Touching can be good.
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
39 40 41 |
# File 'lib/jss-api/ruby_extensions/pathname.rb', line 39 def jss_cp(dest, = {}) FileUtils.cp @path, dest.to_s, end |
#jss_cp_r(dest, options = {}) ⇒ Object
Recursively copy this path to a destination
45 46 47 |
# File 'lib/jss-api/ruby_extensions/pathname.rb', line 45 def jss_cp_r(dest, = {}) FileUtils.cp_r @path, dest.to_s, end |
#jss_real_file? ⇒ Boolean
Is this a real file rather than a symlink?
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_touch ⇒ Object
Touching can be good
69 70 71 |
# File 'lib/jss-api/ruby_extensions/pathname.rb', line 69 def jss_touch FileUtils.touch @path end |