Module: PDK::Util::Filesystem

Included in:
AnswerFile, Generate::Module, Module::Metadata
Defined in:
lib/pdk/util/filesystem.rb

Class Method Summary collapse

Class Method Details

.directory?(*args) ⇒ Boolean

:nocov: These methods just wrap core Ruby functionality and can be ignored for code coverage

Returns:

  • (Boolean)


31
32
33
# File 'lib/pdk/util/filesystem.rb', line 31

def directory?(*args)
  File.directory?(*args)
end

.exist?(*args) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/pdk/util/filesystem.rb', line 66

def exist?(*args)
  File.exist?(*args)
end

.expand_path(*args) ⇒ Object



46
47
48
# File 'lib/pdk/util/filesystem.rb', line 46

def expand_path(*args)
  File.expand_path(*args)
end

.file?(*args) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/pdk/util/filesystem.rb', line 41

def file?(*args)
  File.file?(*args)
end

.fnmatch(*args) ⇒ Object



56
57
58
# File 'lib/pdk/util/filesystem.rb', line 56

def fnmatch(*args)
  File.fnmatch(*args)
end

.glob(*args) ⇒ Object



51
52
53
# File 'lib/pdk/util/filesystem.rb', line 51

def glob(*args)
  Dir.glob(*args)
end

.mkdir_p(*args) ⇒ Object



36
37
38
# File 'lib/pdk/util/filesystem.rb', line 36

def mkdir_p(*args)
  FileUtils.mkdir_p(*args)
end

.read_file(file, nil_on_error: false) ⇒ Object



20
21
22
23
24
25
# File 'lib/pdk/util/filesystem.rb', line 20

def read_file(file, nil_on_error: false)
  File.read(file)
rescue => e
  raise e unless nil_on_error
  nil
end

.readable?(*args) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/pdk/util/filesystem.rb', line 61

def readable?(*args)
  File.readable?(*args)
end

.rm(*args) ⇒ Object



71
72
73
# File 'lib/pdk/util/filesystem.rb', line 71

def rm(*args)
  FileUtils.rm(*args)
end

.write_file(path, content) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/pdk/util/filesystem.rb', line 6

def write_file(path, content)
  raise ArgumentError, _('content must be a String') unless content.is_a?(String)
  raise ArgumentError, _('path must be a String or Pathname') unless path.is_a?(String) || path.respond_to?(:to_path)

  # Harmonize newlines across platforms.
  content = content.encode(universal_newline: true)

  # Make sure all written files have a trailing newline.
  content += "\n" unless content[-1] == "\n"

  File.open(path, 'wb') { |f| f.write(content) }
end