Method: Inspec::RelativeFileProvider#initialize
- Defined in:
- lib/inspec/file_provider.rb
#initialize(parent_provider) ⇒ RelativeFileProvider
Returns a new instance of RelativeFileProvider.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/inspec/file_provider.rb', line 188 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 |