class Inspec::FileProvider

Public Class Methods

for_path(path) click to toggle source
# File lib/inspec/file_provider.rb, line 8
def self.for_path(path)
  if path.is_a?(Hash)
    MockProvider.new(path)
  elsif File.directory?(path)
    DirProvider.new(path)
  elsif File.exist?(path) && path.end_with?(".tar.gz", "tgz")
    TarProvider.new(path)
  elsif File.exist?(path) && path.end_with?(".zip")
    ZipProvider.new(path)
  elsif File.exist?(path)
    DirProvider.new(path)
  else
    raise "No file provider for the provided path: #{path}"
  end
end
new(_path) click to toggle source
# File lib/inspec/file_provider.rb, line 24
def initialize(_path); end

Public Instance Methods

binread(file) click to toggle source

Provide a method for reading binary contents from a file. It will default to read if not defined. For most streams that implement it, it will be the same. For some special cases, it will add change the way in which encoding of the returned data structure is handled. Does not work with alias nor alias_method.

# File lib/inspec/file_provider.rb, line 47
def binread(file)
  read(file)
end
files() click to toggle source

List all files that are offered.

@return [Array] list of file paths that are included

# File lib/inspec/file_provider.rb, line 29
def files
  raise "Fetcher #{self} does not implement `files()`. This is required."
end
read(_file) click to toggle source

Read the contents of a file. This will typically refer to a text file reading a string.

@param _file [String] path of the file to be read @return [String] contents of the file described

# File lib/inspec/file_provider.rb, line 38
def read(_file)
  raise "#{self} does not implement `read(...)`. This is required."
end
relative_provider() click to toggle source
# File lib/inspec/file_provider.rb, line 51
def relative_provider
  RelativeFileProvider.new(self)
end