Class: FileWrapper

Inherits:
Object show all
Defined in:
lib/ceedling/file_wrapper.rb

Instance Method Summary collapse

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, options={})
  FileUtils.cp(source, destination, **options)
end

#cp_r(source, destination, options = {}) ⇒ Object



70
71
72
# File 'lib/ceedling/file_wrapper.rb', line 70

def cp_r(source, destination, options={})
  FileUtils.cp_r(source, destination, **options)
end

#directory?(path) ⇒ Boolean

Is path a directory and does it exist?

Returns:

  • (Boolean)


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

Returns:

  • (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 get_expanded_path(path)
  return File.expand_path(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, options={})
  FileUtils.mv(source, destination, **options)
end

#newer?(filepathA, filepathB) ⇒ Boolean

Is filepath A newer than B?

Returns:

  • (Boolean)


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

Returns:

  • (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, options={})
  FileUtils.rm_f(filepath, **options)
end

#rm_r(filepath, options = {}) ⇒ Object



58
59
60
# File 'lib/ceedling/file_wrapper.rb', line 58

def rm_r(filepath, options={})
  FileUtils.rm_r(filepath, **options={})
end

#rm_rf(path, options = {}) ⇒ Object



62
63
64
# File 'lib/ceedling/file_wrapper.rb', line 62

def rm_rf(path, options={})
  FileUtils.rm_rf(path, **options={})
end

#touch(filepath, options = {}) ⇒ Object



100
101
102
# File 'lib/ceedling/file_wrapper.rb', line 100

def touch(filepath, options={})
  FileUtils.touch(filepath, **options)
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