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



13
14
15
16
# File 'lib/ceedling/file_wrapper.rb', line 13

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

#compare(from, to) ⇒ Object



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

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

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



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

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

#directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#directory_listing(glob) ⇒ Object



31
32
33
# File 'lib/ceedling/file_wrapper.rb', line 31

def directory_listing(glob)
  return Dir.glob(glob, File::FNM_PATHNAME)
end

#dirname(path) ⇒ Object



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

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

#exist?(filepath) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#get_expanded_path(path) ⇒ Object



9
10
11
# File 'lib/ceedling/file_wrapper.rb', line 9

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

#instantiate_file_list(files = []) ⇒ Object



75
76
77
# File 'lib/ceedling/file_wrapper.rb', line 75

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

#mkdir(folder) ⇒ Object



79
80
81
# File 'lib/ceedling/file_wrapper.rb', line 79

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

#open(filepath, flags) ⇒ Object



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

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

#read(filepath) ⇒ Object



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

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

#readlines(filepath) ⇒ Object



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

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

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



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

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

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



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

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

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



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

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

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



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

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