mirror of
https://github.com/inspec/inspec
synced 2024-12-20 18:13:20 +00:00
07cb7efe36
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
31 lines
839 B
Ruby
31 lines
839 B
Ruby
# encoding: utf-8
|
|
require 'vulcano/targets/dir'
|
|
require 'vulcano/targets/file'
|
|
|
|
module Vulcano::Targets
|
|
class FolderHelper
|
|
def handles?(target)
|
|
File.directory?(target)
|
|
end
|
|
|
|
def resolve(target)
|
|
# find all files in the folder
|
|
files = Dir[File.join(target, '**', '*')]
|
|
# remove the prefix
|
|
files = files.map { |x| x[target.length + 1..-1] }
|
|
# get the dirs helper
|
|
helper = DirsHelper.get_handler(files)
|
|
if helper.nil?
|
|
fail "Don't know how to handle folder #{target}"
|
|
end
|
|
# get all file contents
|
|
file_handler = Vulcano::Targets.modules['file']
|
|
test_files = helper.get_filenames(files)
|
|
test_files.map do |f|
|
|
file_handler.resolve(File.join(target, f))
|
|
end
|
|
end
|
|
end
|
|
|
|
Vulcano::Targets.add_module('folder', FolderHelper.new)
|
|
end
|