simplify folder resolver

This commit is contained in:
Dominik Richter 2015-11-02 11:31:09 +01:00
parent 22bf549e0b
commit f410ee3dba
2 changed files with 14 additions and 9 deletions

View file

@ -9,12 +9,20 @@ module Inspec::Targets
end
def resolve(target, opts = {})
key = opts[:as] || :content
base = opts[:base_folder]
path = base.nil? ? target : File.join(base, target)
{
key => File.read(target),
content: File.read(path),
type: opts[:as] || :test,
ref: target,
}
end
def resolve_all(targets, opts = {})
Array(targets).map do |target|
resolve(target, opts)
end
end
end
Inspec::Targets.add_module('file', FileHelper.new)

View file

@ -26,19 +26,16 @@ module Inspec::Targets
# get all test file contents
file_handler = Inspec::Targets.modules['file']
raw_files = helper.get_filenames(files)
files = raw_files.map do |f|
file_handler.resolve(File.join(target, f))
end
tests = file_handler.resolve_all(raw_files, base_folder: target)
libs = []
if helper.respond_to? :get_libraries
raw_libs = helper.get_libraries(files)
libs = raw_libs.map do |f|
file_handler.resolve(File.join(target, f), as: :library)
end
libs = file_handler.resolve_all(raw_libs,
base_folder: target, as: :library)
end
libs + files
libs + tests
end
end