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
end end
def load_all paths def load_all &blk
paths.map { |path| file = @target.read(path); [path, file] if file }.compact.to_h find_all(&blk).map { |path| file = @target.read(path); [path, file] if file }.compact.to_h
end end
def load_tests def load_tests
paths = find_all { |path| load_all { |path|
path.start_with?("controls") && path.end_with?(".rb") path.start_with?("controls") && path.end_with?(".rb")
} }
load_all paths
end end
def load_libs def load_libs
paths = find_all { |path| load_all { |path|
path.start_with?("libraries") && path.end_with?(".rb") path.start_with?("libraries") && path.end_with?(".rb")
} }
load_all paths
end end
def load_data_files def load_data_files
paths = find_all { |path| load_all { |path|
path.start_with?("files" + File::SEPARATOR) path.start_with?("files" + File::SEPARATOR)
} }
load_all paths
end end
end end
end end