From ac6164e56d06e4e83647094a8efcab45e5de3701 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Thu, 8 Aug 2019 14:12:41 -0700 Subject: [PATCH] lib/source_readers/inspec.rb refactor 7/8: combine load_all and find_all. 58.9: flog total Signed-off-by: Ryan Davis --- lib/source_readers/inspec.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/source_readers/inspec.rb b/lib/source_readers/inspec.rb index d4fbc2c40..5682b6614 100644 --- a/lib/source_readers/inspec.rb +++ b/lib/source_readers/inspec.rb @@ -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