Class: FileWrapper

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_include_guard(name) ⇒ Object



17
18
19
20
21
22
# File 'lib/ceedling/file_wrapper.rb', line 17

def self.generate_include_guard(name)
  # abc-XYZ.h --> _ABC_XYZ_H_
  base = File.basename(name, '.*') # Remove any extension
  guard = '__' + CEEDLING_GENERATED + '_' + base.gsub(/\W/, '_').upcase + '_H__'
  return guard
end

Instance Method Details

#basename(path, extension = nil) ⇒ Object



28
29
30
31
# File 'lib/ceedling/file_wrapper.rb', line 28

def basename(path, extension=nil)
  return File.basename(path, extension) if extension
  return File.basename(path)
end

#compare(from, to) ⇒ Object



85
86
87
# File 'lib/ceedling/file_wrapper.rb', line 85

def compare(from, to)
  return FileUtils.compare_file(from, to)
end

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



73
74
75
# File 'lib/ceedling/file_wrapper.rb', line 73

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

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



77
78
79
# File 'lib/ceedling/file_wrapper.rb', line 77

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)


43
44
45
# File 'lib/ceedling/file_wrapper.rb', line 43

def directory?(path)
  return File.directory?(path)
end

#directory_listing(glob) ⇒ Object



55
56
57
58
59
# File 'lib/ceedling/file_wrapper.rb', line 55

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



51
52
53
# File 'lib/ceedling/file_wrapper.rb', line 51

def dirname(path)
  return File.dirname(path)
end

#exist?(filepath) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/ceedling/file_wrapper.rb', line 33

def exist?(filepath)
  return true if (filepath == NULL_FILE_PATH)
  return File.exist?(filepath)
end

#extname(filepath) ⇒ Object



38
39
40
# File 'lib/ceedling/file_wrapper.rb', line 38

def extname(filepath)
  return File.extname(filepath)
end

#get_expanded_path(path) ⇒ Object



24
25
26
# File 'lib/ceedling/file_wrapper.rb', line 24

def get_expanded_path(path)
  return File.expand_path(path)
end

#instantiate_file_list(files = []) ⇒ Object



127
128
129
# File 'lib/ceedling/file_wrapper.rb', line 127

def instantiate_file_list(files=[])
  return FileList.new(files)
end

#mkdir(folder) ⇒ Object



131
132
133
# File 'lib/ceedling/file_wrapper.rb', line 131

def mkdir(folder)
  return FileUtils.mkdir_p(folder)
end

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



81
82
83
# File 'lib/ceedling/file_wrapper.rb', line 81

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

#newer?(filepathA, filepathB) ⇒ Boolean

Is filepath A newer than B?

Returns:

  • (Boolean)


90
91
92
93
94
95
# File 'lib/ceedling/file_wrapper.rb', line 90

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



97
98
99
100
101
# File 'lib/ceedling/file_wrapper.rb', line 97

def open(filepath, flags)
  File.open(filepath, flags) do |file|
    yield(file)
  end
end

#read(filepath, length = nil) ⇒ Object



103
104
105
# File 'lib/ceedling/file_wrapper.rb', line 103

def read(filepath, length=nil)
  return File.read(filepath, length)
end

#readlines(filepath) ⇒ Object



123
124
125
# File 'lib/ceedling/file_wrapper.rb', line 123

def readlines(filepath)
  return File.readlines(filepath)
end

#relative?(path) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/ceedling/file_wrapper.rb', line 47

def relative?(path)
  return Pathname.new( path).relative?
end

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



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

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

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



65
66
67
# File 'lib/ceedling/file_wrapper.rb', line 65

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

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



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

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

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



107
108
109
# File 'lib/ceedling/file_wrapper.rb', line 107

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

#write(filepath, contents, flags = 'w') ⇒ Object



117
118
119
120
121
# File 'lib/ceedling/file_wrapper.rb', line 117

def write(filepath, contents, flags='w')
  File.open(filepath, flags) do |file|
    file.write(contents)
  end
end

#write_blank_file(filepath) ⇒ Object



111
112
113
114
115
# File 'lib/ceedling/file_wrapper.rb', line 111

def write_blank_file(filepath)
  File.open(filepath, 'w') do |file|
    file.write("// Ceedling intentionally blank file\n\n")
  end
end