Class: Facter::Util::FileHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/facter/util/file_helper.rb

Constant Summary collapse

DEBUG_MESSAGE =
'File at: %s is not accessible.'

Class Method Summary collapse

Class Method Details

.dir_children(path) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/facter/util/file_helper.rb', line 25

def dir_children(path)
  children = if RUBY_VERSION.to_f < 2.5
               Dir.entries(path).reject { |dir| ['.', '..'].include?(dir) }
             else
               Dir.children(path)
             end

  children
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 = []) ⇒ Object



18
19
20
21
22
23
# File 'lib/facter/util/file_helper.rb', line 18

def safe_readlines(path, default_return = [])
  return File.readlines(path, encoding: Encoding::UTF_8) if File.readable?(path)

  log_failed_to_read(path)
  default_return
end