Class: Inspec::RelativeFileProvider

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

Overview

class IafProvider

Constant Summary collapse

BLACKLIST_FILES =
[
  "/pax_global_header",
  "pax_global_header",
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_provider) ⇒ RelativeFileProvider

Returns a new instance of RelativeFileProvider.



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/inspec/file_provider.rb', line 265

def initialize(parent_provider)
  @parent = parent_provider
  @prefix = get_prefix(parent.files)
  if @prefix.nil?
    raise "Could not determine path prefix for #{parent}"
  end

  # select all files that begin with the prefix, and strip off the prefix from the file.
  #
  # strip off any leading top-level relative path (./) which is common in
  # PAX-formatted tar files. Do not do any translation of the path if the
  # path is an absolute path.
  @files = parent.files
    .find_all { |x| x.start_with?(prefix) && x != prefix }
    .map { |x| x[prefix.length..-1] }
    .map do |x|
      path = Pathname.new(x)
      path.absolute? ? path.to_s : path.relative_path_from(Pathname.new(".")).to_s
    end
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



261
262
263
# File 'lib/inspec/file_provider.rb', line 261

def files
  @files
end

#parentObject (readonly)

Returns the value of attribute parent.



263
264
265
# File 'lib/inspec/file_provider.rb', line 263

def parent
  @parent
end

#prefixObject (readonly)

Returns the value of attribute prefix.



262
263
264
# File 'lib/inspec/file_provider.rb', line 262

def prefix
  @prefix
end

Instance Method Details

#abs_path(file) ⇒ Object



286
287
288
289
290
# File 'lib/inspec/file_provider.rb', line 286

def abs_path(file)
  return nil if file.nil?

  prefix + file
end

#binread(file) ⇒ Object



296
297
298
# File 'lib/inspec/file_provider.rb', line 296

def binread(file)
  parent.binread(abs_path(file))
end

#read(file) ⇒ Object



292
293
294
# File 'lib/inspec/file_provider.rb', line 292

def read(file)
  parent.read(abs_path(file))
end