Sha256: fa63819da860e457c245d1be000ee1af8df94aef5064ce4cfecbcfbd512f4c60

Contents?: true

Size: 1.01 KB

Versions: 10

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Facter
  module Util
    class FileHelper
      @log = Log.new(self)

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

        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

        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

        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

        private

        def log_failed_to_read(path)
          @log.debug(DEBUG_MESSAGE % path)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facter-4.4.3 lib/facter/util/file_helper.rb
facter-4.4.2 lib/facter/util/file_helper.rb
facter-4.4.1 lib/facter/util/file_helper.rb
facter-4.4.0 lib/facter/util/file_helper.rb
facter-4.3.1 lib/facter/util/file_helper.rb
facter-4.3.0 lib/facter/util/file_helper.rb
facter-4.2.14 lib/facter/util/file_helper.rb
facter-4.2.13 lib/facter/util/file_helper.rb
facter-4.2.12 lib/facter/util/file_helper.rb
facter-4.2.11 lib/facter/util/file_helper.rb