Class: Inspec::FileProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/file_provider.rb

Direct Known Subclasses

DirProvider, MockProvider, TarProvider, ZipProvider

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_path) ⇒ FileProvider

Returns a new instance of FileProvider.



24
25
# File 'lib/inspec/file_provider.rb', line 24

def initialize(_path)
end

Class Method Details

.for_path(path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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

Instance Method Details

#binread(file) ⇒ Object

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.



48
49
50
# File 'lib/inspec/file_provider.rb', line 48

def binread(file)
  read(file)
end

#filesArray[String]

List all files that are offered.

Returns:

  • (Array[String])

    list of file paths that are included



30
31
32
# File 'lib/inspec/file_provider.rb', line 30

def files
  raise "Fetcher #{self} does not implement `files()`. This is required."
end

#read(_file) ⇒ String

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

Parameters:

  • _file (String)

    path of the file to be read

Returns:

  • (String)

    contents of the file described



39
40
41
# File 'lib/inspec/file_provider.rb', line 39

def read(_file)
  raise "#{self} does not implement `read(...)`. This is required."
end

#relative_providerObject



52
53
54
# File 'lib/inspec/file_provider.rb', line 52

def relative_provider
  RelativeFileProvider.new(self)
end