Class: Inspec::FileProvider
- Inherits:
-
Object
- Object
- Inspec::FileProvider
- Defined in:
- lib/inspec/file_provider.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#binread(file) ⇒ Object
Provide a method for reading binary contents from a file.
-
#files ⇒ Array[String]
List all files that are offered.
-
#initialize(_path) ⇒ FileProvider
constructor
A new instance of FileProvider.
-
#read(_file) ⇒ String
Read the contents of a file.
- #relative_provider ⇒ Object
Constructor Details
#initialize(_path) ⇒ FileProvider
Returns a new instance of FileProvider.
32 |
# File 'lib/inspec/file_provider.rb', line 32 def initialize(_path); end |
Class Method Details
.for_path(path) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/inspec/file_provider.rb', line 9 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) && path.end_with?(".iaf") iaf_file = IafFile.new(path) if iaf_file.valid? IafProvider.new(path) else raise Inspec::InvalidProfileSignature, "Profile signature is invalid." end 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.
55 56 57 |
# File 'lib/inspec/file_provider.rb', line 55 def binread(file) read(file) end |
#files ⇒ Array[String]
List all files that are offered.
37 38 39 |
# File 'lib/inspec/file_provider.rb', line 37 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.
46 47 48 |
# File 'lib/inspec/file_provider.rb', line 46 def read(_file) raise "#{self} does not implement `read(...)`. This is required." end |
#relative_provider ⇒ Object
59 60 61 |
# File 'lib/inspec/file_provider.rb', line 59 def relative_provider RelativeFileProvider.new(self) end |