Sha256: 1c0ff8501afbed286b5654ce144e7060494297bf7e9a93e1085f8e3a5ece2826

Contents?: true

Size: 1.15 KB

Versions: 121

Compression:

Stored size: 1.15 KB

Contents

module Facter
module Util

# {Facter::Util::FileRead} is a utility module intended to provide easily
# mockable methods that delegate to simple file read methods.  The intent is to
# avoid the need to execute the `cat` system command or `File.read` directly in
# Ruby, as mocking these behaviors can have wide-ranging effects.
#
# All Facter facts are encouraged to use this method instead of File.read or
# Facter::Core::Execution.exec('cat ...')
#
# @api public
module FileRead
  # read returns the raw content of a file as a string.  If the file does not
  # exist, or the process does not have permission to read the file then nil is
  # returned.
  #
  # @api public
  #
  # @param path [String] the path to be read
  #
  # @return [String, nil] the raw contents of the file or `nil` if the
  #   file cannot be read because it does not exist or the process does not have
  #   permission to read the file.
  def self.read(path)
    File.read(path)
  rescue Errno::ENOENT, Errno::EACCES => detail
    Facter.debug "Could not read #{path}: #{detail.message}"
    nil
  end

  def self.read_binary(path)
    File.open(path, "rb") { |contents| contents.read }
  end
end
end
end

Version data entries

121 entries across 121 versions & 2 rubygems

Version Path
facter-2.5.7 lib/facter/util/file_read.rb
facter-2.5.7-x86-mingw32 lib/facter/util/file_read.rb
facter-2.5.7-x64-mingw32 lib/facter/util/file_read.rb
facter-2.5.7-universal-darwin lib/facter/util/file_read.rb
facter-2.5.6-x86-mingw32 lib/facter/util/file_read.rb
facter-2.5.6-x64-mingw32 lib/facter/util/file_read.rb
facter-2.5.6-universal-darwin lib/facter/util/file_read.rb
facter-2.5.6 lib/facter/util/file_read.rb
facter-2.5.5-x86-mingw32 lib/facter/util/file_read.rb
facter-2.5.5-x64-mingw32 lib/facter/util/file_read.rb
facter-2.5.5-universal-darwin lib/facter/util/file_read.rb
facter-2.5.5 lib/facter/util/file_read.rb
facter-2.5.4-x86-mingw32 lib/facter/util/file_read.rb
facter-2.5.4-x64-mingw32 lib/facter/util/file_read.rb
facter-2.5.4-universal-darwin lib/facter/util/file_read.rb
facter-2.5.4 lib/facter/util/file_read.rb
bolt-0.24.0 vendored/facter/lib/facter/util/file_read.rb
bolt-0.23.0 vendored/facter/lib/facter/util/file_read.rb
bolt-0.22.0 vendored/facter/lib/facter/util/file_read.rb
bolt-0.21.8 vendored/facter/lib/facter/util/file_read.rb