Class: FileUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/yesman/file_util.rb

Class Method Summary collapse

Class Method Details

.clear_directory(path) ⇒ Object



15
16
17
18
# File 'lib/yesman/file_util.rb', line 15

def self.clear_directory path
  self.kill_directory path
  self.ensure_path path 
end

.ensure_file(path) ⇒ Object



3
4
5
6
7
8
# File 'lib/yesman/file_util.rb', line 3

def self.ensure_file path
  dirs = self.determine_path path
  filename = dirs.pop
  self.create_directories dirs
  self.verify_or_make_file path
end

.ensure_path(path) ⇒ Object



10
11
12
13
# File 'lib/yesman/file_util.rb', line 10

def self.ensure_path path
  dirs = self.determine_path path
  self.create_directories dirs
end

.kill_directory(path) ⇒ Object



20
21
22
# File 'lib/yesman/file_util.rb', line 20

def self.kill_directory path
  `rm -rf #{path}` unless (!File.exists? path) || (!File.directory? path)
end

.kill_file(filename) ⇒ Object



24
25
26
# File 'lib/yesman/file_util.rb', line 24

def self.kill_file filename
  `rm #{filename}` unless !File.exists? filename
end

.recursive_copy(from, to) ⇒ Object



28
29
30
# File 'lib/yesman/file_util.rb', line 28

def self.recursive_copy from, to
  `cp -r #{from} #{to}`
end

.write_to_file(filename, contents) ⇒ Object



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

def self.write_to_file filename, contents
  self.ensure_file filename
  File.open( filename, "w" ) { |f| f.write( contents ) }
end