Class: Inspec::RelativeFileProvider

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

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.



147
148
149
150
151
152
153
154
155
# File 'lib/inspec/file_provider.rb', line 147

def initialize(parent_provider)
  @parent = parent_provider
  @prefix = get_prefix(parent.files)
  if @prefix.nil?
    raise "Could not determine path prefix for #{parent}"
  end
  @files = parent.files.find_all { |x| x.start_with?(prefix) && x != prefix }
                 .map { |x| x[prefix.length..-1] }
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



143
144
145
# File 'lib/inspec/file_provider.rb', line 143

def files
  @files
end

#parentObject (readonly)

Returns the value of attribute parent.



145
146
147
# File 'lib/inspec/file_provider.rb', line 145

def parent
  @parent
end

#prefixObject (readonly)

Returns the value of attribute prefix.



144
145
146
# File 'lib/inspec/file_provider.rb', line 144

def prefix
  @prefix
end

Instance Method Details

#abs_path(file) ⇒ Object



157
158
159
160
# File 'lib/inspec/file_provider.rb', line 157

def abs_path(file)
  return nil if file.nil?
  prefix + file
end

#read(file) ⇒ Object



162
163
164
# File 'lib/inspec/file_provider.rb', line 162

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