Module: PDK::Util::Filesystem
- Included in:
- AnswerFile, Generate::Module, Module::Metadata
- Defined in:
- lib/pdk/util/filesystem.rb
Class Method Summary collapse
-
.directory?(*args) ⇒ Boolean
:nocov: These methods just wrap core Ruby functionality and can be ignored for code coverage.
- .exist?(*args) ⇒ Boolean
- .expand_path(*args) ⇒ Object
- .file?(*args) ⇒ Boolean
- .fnmatch(*args) ⇒ Object
- .glob(*args) ⇒ Object
- .mkdir_p(*args) ⇒ Object
- .read_file(file, nil_on_error: false) ⇒ Object
- .readable?(*args) ⇒ Boolean
- .rm(*args) ⇒ Object
- .write_file(path, content) ⇒ Object
Class Method Details
.directory?(*args) ⇒ Boolean
:nocov: These methods just wrap core Ruby functionality and can be ignored for code coverage
28 29 30 |
# File 'lib/pdk/util/filesystem.rb', line 28 def directory?(*args) File.directory?(*args) end |
.exist?(*args) ⇒ Boolean
63 64 65 |
# File 'lib/pdk/util/filesystem.rb', line 63 def exist?(*args) File.exist?(*args) end |
.expand_path(*args) ⇒ Object
43 44 45 |
# File 'lib/pdk/util/filesystem.rb', line 43 def (*args) File.(*args) end |
.file?(*args) ⇒ Boolean
38 39 40 |
# File 'lib/pdk/util/filesystem.rb', line 38 def file?(*args) File.file?(*args) end |
.fnmatch(*args) ⇒ Object
53 54 55 |
# File 'lib/pdk/util/filesystem.rb', line 53 def fnmatch(*args) File.fnmatch(*args) end |
.glob(*args) ⇒ Object
48 49 50 |
# File 'lib/pdk/util/filesystem.rb', line 48 def glob(*args) Dir.glob(*args) end |
.mkdir_p(*args) ⇒ Object
33 34 35 |
# File 'lib/pdk/util/filesystem.rb', line 33 def mkdir_p(*args) FileUtils.mkdir_p(*args) end |
.read_file(file, nil_on_error: false) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/pdk/util/filesystem.rb', line 17 def read_file(file, nil_on_error: false) File.read(file) rescue => e raise e unless nil_on_error nil end |
.readable?(*args) ⇒ Boolean
58 59 60 |
# File 'lib/pdk/util/filesystem.rb', line 58 def readable?(*args) File.readable?(*args) end |
.rm(*args) ⇒ Object
68 69 70 |
# File 'lib/pdk/util/filesystem.rb', line 68 def rm(*args) FileUtils.rm(*args) end |
.write_file(path, content) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/pdk/util/filesystem.rb', line 4 def write_file(path, content) raise ArgumentError 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 |