inspec/lib/vulcano/targets/folder.rb

35 lines
895 B
Ruby
Raw Normal View History

# encoding: utf-8
2015-10-06 16:55:44 +00:00
# author: Dominik Richter
# author: Christoph Hartmann
require 'vulcano/targets/dir'
require 'vulcano/targets/file'
module Vulcano::Targets
class FolderHelper
def handles?(target)
2015-09-04 07:15:20 +00:00
File.directory?(target)
end
def resolve(target)
# find all files in the folder
2015-09-05 14:07:54 +00:00
files = Dir[File.join(target, '**', '*')]
# remove the prefix
2015-09-05 14:07:54 +00:00
files = files.map { |x| x[target.length + 1..-1] }
# get the dirs helper
helper = DirsHelper.get_handler(files)
if helper.nil?
2015-09-03 21:24:42 +00:00
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|
2015-09-05 14:07:54 +00:00
file_handler.resolve(File.join(target, f))
end
end
end
Vulcano::Targets.add_module('folder', FolderHelper.new)
end