Class: Fancypath

Inherits:
Pathname show all
Defined in:
lib/fancypath.rb

Instance Method Summary collapse

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

#createObject

make dir



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

def create
  mkpath unless exist?
  self.to_path
end

#inspectObject



68
69
70
# File 'lib/fancypath.rb', line 68

def inspect
  super.sub('Pathname','Fancypath')
end

#removeObject

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_pathObject



72
73
74
# File 'lib/fancypath.rb', line 72

def to_path
  self
end

#touchObject

make file



32
33
34
35
# File 'lib/fancypath.rb', line 32

def touch
  FileUtils.touch self.to_s
  self.to_path
end

#visible_childrenObject



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