Class: FileWrapper
Instance Method Summary collapse
- #basename(path, extension = nil) ⇒ Object
- #compare(from, to) ⇒ Object
- #cp(source, destination, options = {}) ⇒ Object
- #cp_r(source, destination, options = {}) ⇒ Object
-
#directory?(path) ⇒ Boolean
Is path a directory and does it exist?.
- #directory_listing(glob) ⇒ Object
- #dirname(path) ⇒ Object
- #exist?(filepath) ⇒ Boolean
- #extname(filepath) ⇒ Object
- #get_expanded_path(path) ⇒ Object
- #instantiate_file_list(files = []) ⇒ Object
- #mkdir(folder) ⇒ Object
- #mv(source, destination, options = {}) ⇒ Object
-
#newer?(filepathA, filepathB) ⇒ Boolean
Is filepath A newer than B?.
- #open(filepath, flags) ⇒ Object
- #read(filepath, length = nil) ⇒ Object
- #readlines(filepath) ⇒ Object
- #relative?(path) ⇒ Boolean
- #rm_f(filepath, options = {}) ⇒ Object
- #rm_r(filepath, options = {}) ⇒ Object
- #rm_rf(path, options = {}) ⇒ Object
- #touch(filepath, options = {}) ⇒ Object
- #write(filepath, contents, flags = 'w') ⇒ Object
Instance Method Details
#basename(path, extension = nil) ⇒ Object
21 22 23 24 |
# File 'lib/ceedling/file_wrapper.rb', line 21 def basename(path, extension=nil) return File.basename(path, extension) if extension return File.basename(path) end |
#compare(from, to) ⇒ Object
78 79 80 |
# File 'lib/ceedling/file_wrapper.rb', line 78 def compare(from, to) return FileUtils.compare_file(from, to) end |
#cp(source, destination, options = {}) ⇒ Object
66 67 68 |
# File 'lib/ceedling/file_wrapper.rb', line 66 def cp(source, destination, ={}) FileUtils.cp(source, destination, **) end |
#cp_r(source, destination, options = {}) ⇒ Object
70 71 72 |
# File 'lib/ceedling/file_wrapper.rb', line 70 def cp_r(source, destination, ={}) FileUtils.cp_r(source, destination, **) end |
#directory?(path) ⇒ Boolean
Is path a directory and does it exist?
36 37 38 |
# File 'lib/ceedling/file_wrapper.rb', line 36 def directory?(path) return File.directory?(path) end |
#directory_listing(glob) ⇒ Object
48 49 50 51 52 |
# File 'lib/ceedling/file_wrapper.rb', line 48 def directory_listing(glob) # Note: `sort()` to ensure platform-independent directory listings (Github Issue #860) # FNM_PATHNAME => Case insensitive globs return Dir.glob(glob, File::FNM_PATHNAME).sort() end |
#dirname(path) ⇒ Object
44 45 46 |
# File 'lib/ceedling/file_wrapper.rb', line 44 def dirname(path) return File.dirname(path) end |
#exist?(filepath) ⇒ Boolean
26 27 28 29 |
# File 'lib/ceedling/file_wrapper.rb', line 26 def exist?(filepath) return true if (filepath == NULL_FILE_PATH) return File.exist?(filepath) end |
#extname(filepath) ⇒ Object
31 32 33 |
# File 'lib/ceedling/file_wrapper.rb', line 31 def extname(filepath) return File.extname(filepath) end |
#get_expanded_path(path) ⇒ Object
17 18 19 |
# File 'lib/ceedling/file_wrapper.rb', line 17 def (path) return File.(path) end |
#instantiate_file_list(files = []) ⇒ Object
114 115 116 |
# File 'lib/ceedling/file_wrapper.rb', line 114 def instantiate_file_list(files=[]) return FileList.new(files) end |
#mkdir(folder) ⇒ Object
118 119 120 |
# File 'lib/ceedling/file_wrapper.rb', line 118 def mkdir(folder) return FileUtils.mkdir_p(folder) end |
#mv(source, destination, options = {}) ⇒ Object
74 75 76 |
# File 'lib/ceedling/file_wrapper.rb', line 74 def mv(source, destination, ={}) FileUtils.mv(source, destination, **) end |
#newer?(filepathA, filepathB) ⇒ Boolean
Is filepath A newer than B?
83 84 85 86 87 88 |
# File 'lib/ceedling/file_wrapper.rb', line 83 def newer?(filepathA, filepathB) return false unless File.exist?(filepathA) return false unless File.exist?(filepathB) return (File.mtime(filepathA) > File.mtime(filepathB)) end |
#open(filepath, flags) ⇒ Object
90 91 92 93 94 |
# File 'lib/ceedling/file_wrapper.rb', line 90 def open(filepath, flags) File.open(filepath, flags) do |file| yield(file) end end |
#read(filepath, length = nil) ⇒ Object
96 97 98 |
# File 'lib/ceedling/file_wrapper.rb', line 96 def read(filepath, length=nil) return File.read(filepath, length) end |
#readlines(filepath) ⇒ Object
110 111 112 |
# File 'lib/ceedling/file_wrapper.rb', line 110 def readlines(filepath) return File.readlines(filepath) end |
#relative?(path) ⇒ Boolean
40 41 42 |
# File 'lib/ceedling/file_wrapper.rb', line 40 def relative?(path) return Pathname.new( path).relative? end |
#rm_f(filepath, options = {}) ⇒ Object
54 55 56 |
# File 'lib/ceedling/file_wrapper.rb', line 54 def rm_f(filepath, ={}) FileUtils.rm_f(filepath, **) end |
#rm_r(filepath, options = {}) ⇒ Object
58 59 60 |
# File 'lib/ceedling/file_wrapper.rb', line 58 def rm_r(filepath, ={}) FileUtils.rm_r(filepath, **={}) end |
#rm_rf(path, options = {}) ⇒ Object
62 63 64 |
# File 'lib/ceedling/file_wrapper.rb', line 62 def rm_rf(path, ={}) FileUtils.rm_rf(path, **={}) end |
#touch(filepath, options = {}) ⇒ Object
100 101 102 |
# File 'lib/ceedling/file_wrapper.rb', line 100 def touch(filepath, ={}) FileUtils.touch(filepath, **) end |
#write(filepath, contents, flags = 'w') ⇒ Object
104 105 106 107 108 |
# File 'lib/ceedling/file_wrapper.rb', line 104 def write(filepath, contents, flags='w') File.open(filepath, flags) do |file| file.write(contents) end end |