Class: Inspec::DirProvider

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FileProvider

for_path, #relative_provider

Constructor Details

#initialize(path) ⇒ DirProvider

Returns a new instance of DirProvider.



78
79
80
81
82
83
84
85
# File 'lib/inspec/file_provider.rb', line 78

def initialize(path)
  @files = if File.file?(path)
             [path]
           else
             Dir[File.join(Shellwords.shellescape(path), "**", "*")]
           end
  @path = path
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



77
78
79
# File 'lib/inspec/file_provider.rb', line 77

def files
  @files
end

#pathObject (readonly)

Returns the value of attribute path.



77
78
79
# File 'lib/inspec/file_provider.rb', line 77

def path
  @path
end

Instance Method Details

#binread(file) ⇒ Object



94
95
96
97
98
99
# File 'lib/inspec/file_provider.rb', line 94

def binread(file)
  return nil unless files.include?(file)
  return nil unless File.file?(file)

  File.binread(file)
end

#read(file) ⇒ Object



87
88
89
90
91
92
# File 'lib/inspec/file_provider.rb', line 87

def read(file)
  return nil unless files.include?(file)
  return nil unless File.file?(file)

  File.read(file)
end