Class: Fancypath
Instance Method Summary collapse
- #/(path) ⇒ Object
- #append(contents) ⇒ Object
- #copy(dest) ⇒ Object
-
#create ⇒ Object
make dir.
- #inspect ⇒ Object
-
#remove ⇒ Object
file or dir.
- #to_path ⇒ Object
-
#touch ⇒ Object
make file.
- #visible_children ⇒ Object
- #write(contents, mode = 'wb') ⇒ Object
Instance Method Details
#/(path) ⇒ Object
27 28 29 |
# File 'lib/fancypath.rb', line 27 def /(path) self.join(path).to_path end |
#append(contents) ⇒ Object
60 61 62 |
# File 'lib/fancypath.rb', line 60 def append(contents) write(contents,'a+') end |
#copy(dest) ⇒ Object
43 44 45 46 |
# File 'lib/fancypath.rb', line 43 def copy(dest) FileUtils.cp(self, dest) self end |
#create ⇒ Object
make dir
38 39 40 41 |
# File 'lib/fancypath.rb', line 38 def create mkpath unless exist? self.to_path end |
#inspect ⇒ Object
68 69 70 |
# File 'lib/fancypath.rb', line 68 def inspect super.sub('Pathname','Fancypath') end |
#remove ⇒ Object
file or dir
49 50 51 52 |
# File 'lib/fancypath.rb', line 49 def remove directory? ? rmtree : delete if exist? self.to_path end |
#to_path ⇒ Object
72 73 74 |
# File 'lib/fancypath.rb', line 72 def to_path self end |
#touch ⇒ Object
make file
32 33 34 35 |
# File 'lib/fancypath.rb', line 32 def touch FileUtils.touch self.to_s self.to_path end |
#visible_children ⇒ Object
64 65 66 |
# File 'lib/fancypath.rb', line 64 def visible_children children.reject { |c| c.basename.to_s =~ /^\./ } end |
#write(contents, mode = 'wb') ⇒ Object
54 55 56 57 58 |
# File 'lib/fancypath.rb', line 54 def write(contents, mode='wb') dirname.create open(mode) { |f| f.write contents } self.to_path end |