Class: Inspec::Targets::ArchiveHelper

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

Direct Known Subclasses

TarHelper, ZipHelper

Instance Method Summary collapse

Instance Method Details

#resolve(target, _opts = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/inspec/targets/archive.rb', line 10

def resolve(target, _opts = {})
  files, rootdir = structure(target)

  # remove trailing slashes
  files = files.collect { |f| f.chomp('/') }

  # remove leading directory
  files = files.collect { |f|
    Pathname(f).relative_path_from(Pathname(rootdir)).to_s
  }

  helper = DirsHelper.get_handler(files)
  if helper.nil?
    fail "Don't know how to handle folder #{target}"
  end

  # get all test file contents
  raw_files = helper.get_filenames(files)
  tests = content(target, raw_files, rootdir, base_folder: target)

  libs = []
  if helper.respond_to? :get_libraries
    raw_libs = helper.get_libraries(files)
    libs = content(target, raw_libs, rootdir, base_folder: target, as: :library)
  end

  libs + tests
end