Class: Facter::Util::FileHelper
- Inherits:
-
Object
- Object
- Facter::Util::FileHelper
- Defined in:
- lib/facter/util/file_helper.rb
Constant Summary collapse
- DEBUG_MESSAGE =
'File at: %s is not accessible.'
Class Method Summary collapse
-
.dir_children(path) ⇒ Object
This previously acted as a helper method for versions of Ruby older than 2.5, before Dir.children was added.
- .safe_read(path, default_return = '') ⇒ Object
-
.safe_readlines(path, default_return = [], sep = $/, chomp: false) ⇒ Object
rubocop:disable Style/SpecialGlobalVars.
Class Method Details
.dir_children(path) ⇒ Object
This previously acted as a helper method for versions of Ruby older than 2.5, before Dir.children was added. As it isn’t a private method, we can’t remove it entirely until the next major Facter release (presumably Facter 5).
31 32 33 |
# File 'lib/facter/util/file_helper.rb', line 31 def dir_children(path) Dir.children(path) end |
.safe_read(path, default_return = '') ⇒ Object
11 12 13 14 15 16 |
# File 'lib/facter/util/file_helper.rb', line 11 def safe_read(path, default_return = '') return File.read(path, encoding: Encoding::UTF_8) if File.readable?(path) log_failed_to_read(path) default_return end |
.safe_readlines(path, default_return = [], sep = $/, chomp: false) ⇒ Object
rubocop:disable Style/SpecialGlobalVars
19 20 21 22 23 24 |
# File 'lib/facter/util/file_helper.rb', line 19 def safe_readlines(path, default_return = [], sep = $/, chomp: false) return File.readlines(path, sep, chomp: chomp, encoding: Encoding::UTF_8) if File.readable?(path) log_failed_to_read(path) default_return end |