Sha256: 7896f5d64d5f723786f2efc22225adffb91ce2580e8b6240947f881e5d33aab1

Contents?: true

Size: 752 Bytes

Versions: 111

Compression:

Stored size: 752 Bytes

Contents

# encoding: utf-8
# author: ERAMOTO Masaya

module FileReader
  def read_file_content(path, allow_empty = false)
    # these are currently ResourceSkipped to maintain consistency with the resource
    # pre-refactor (which used skip_resource). These should likely be changed to
    # ResourceFailed during a major version bump.
    file = inspec.file(path)
    if !file.file?
      raise Inspec::Exceptions::ResourceSkipped, "Can't find file: #{path}"
    end

    raw_content = file.content
    if raw_content.nil?
      raise Inspec::Exceptions::ResourceSkipped, "Can't read file: #{path}"
    end

    if !allow_empty && raw_content.empty?
      raise Inspec::Exceptions::ResourceSkipped, "File is empty: #{path}"
    end

    raw_content
  end
end

Version data entries

111 entries across 111 versions & 2 rubygems

Version Path
inspec-core-4.3.2 lib/utils/file_reader.rb
inspec-4.3.2 lib/utils/file_reader.rb
inspec-core-4.2.0.preview lib/utils/file_reader.rb
inspec-4.2.0.preview lib/utils/file_reader.rb
inspec-core-4.1.4.preview lib/utils/file_reader.rb
inspec-4.1.4.preview lib/utils/file_reader.rb
inspec-core-3.9.3 lib/utils/file_reader.rb
inspec-3.9.3 lib/utils/file_reader.rb
inspec-core-3.9.0 lib/utils/file_reader.rb
inspec-3.9.0 lib/utils/file_reader.rb
inspec-core-3.7.11 lib/utils/file_reader.rb
inspec-3.7.11 lib/utils/file_reader.rb
inspec-core-3.7.1 lib/utils/file_reader.rb
inspec-3.7.1 lib/utils/file_reader.rb
inspec-core-3.6.6 lib/utils/file_reader.rb
inspec-3.6.6 lib/utils/file_reader.rb
inspec-core-3.6.4 lib/utils/file_reader.rb
inspec-3.6.4 lib/utils/file_reader.rb
inspec-core-2.3.28 lib/utils/file_reader.rb
inspec-2.3.28 lib/utils/file_reader.rb