Class: Inspec::TarProvider

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FileProvider

#binread, for_path, #relative_provider

Constructor Details

#initialize(path) ⇒ TarProvider

Returns a new instance of TarProvider.



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/inspec/file_provider.rb', line 135

def initialize(path)
  @path = path
  @contents = {}
  @files = []
  walk_tar(@path) do |tar|
    @files = tar.find_all(&:file?)

    # delete all entries with no name
    @files = @files.find_all { |x| !x.full_name.empty? }

    # delete all entries that have a PaxHeader
    @files = @files.delete_if { |x| x.full_name.include?('PaxHeader/') }

    # replace all items of the array simply with the relative filename of the file
    @files.map! { |x| Pathname.new(x.full_name).relative_path_from(Pathname.new('.')).to_s }
  end
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



133
134
135
# File 'lib/inspec/file_provider.rb', line 133

def files
  @files
end

Instance Method Details

#read(file) ⇒ Object



153
154
155
# File 'lib/inspec/file_provider.rb', line 153

def read(file)
  @contents[file] ||= read_from_tar(file)
end