lib/source_readers/inspec.rb refactor 7/8: combine load_all and find_all.

58.9: flog total

Signed-off-by: Ryan Davis <zenspider@chef.io>
This commit is contained in:
Ryan Davis 2019-08-08 14:12:41 -07:00
parent 213a4489ed
commit ac6164e56d

View file

@ -46,29 +46,26 @@ module SourceReaders
end
end
def load_all paths
paths.map { |path| file = @target.read(path); [path, file] if file }.compact.to_h
def load_all &blk
find_all(&blk).map { |path| file = @target.read(path); [path, file] if file }.compact.to_h
end
def load_tests
paths = find_all { |path|
load_all { |path|
path.start_with?("controls") && path.end_with?(".rb")
}
load_all paths
end
def load_libs
paths = find_all { |path|
load_all { |path|
path.start_with?("libraries") && path.end_with?(".rb")
}
load_all paths
end
def load_data_files
paths = find_all { |path|
load_all { |path|
path.start_with?("files" + File::SEPARATOR)
}
load_all paths
end
end
end