Class: Inspec::Targets::FolderHelper

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

Instance Method Summary collapse

Instance Method Details

#handles?(target) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/inspec/targets/folder.rb', line 10

def handles?(target)
  File.directory?(target)
end

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



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

def resolve(target, _opts = {})
  # find all files in the folder
  files = Dir[File.join(target, '**', '*')]
  # remove the prefix
  prefix = File.join(target, '')
  files = files.map { |x| x.sub(prefix, '') }
  # get the dirs helper
  helper = DirsHelper.get_handler(files)
  if helper.nil?
    fail "Don't know how to handle folder #{target}"
  end

  # get all test file contents
  file_handler = Inspec::Targets.modules['file']
  res = {
    test:     collect(helper, files, :get_filenames),
    library:  collect(helper, files, :get_libraries),
    metadata: collect(helper, files, :get_metadata),
  }.map { |as, list|
    file_handler.resolve_all(list, base_folder: target, as: as)
  }

  # flatten the outer list layer
  res.inject(&:+)
end

#to_sObject



40
41
42
# File 'lib/inspec/targets/folder.rb', line 40

def to_s
  'Folder Loader'
end