Sha256: eaef942b838053308e91886e2e1d3c075fd3b93991bb8a0e2d0fc32106b25b95
Contents?: true
Size: 806 Bytes
Versions: 5
Compression:
Stored size: 806 Bytes
Contents
require 'json' module TestFileFinder module MappingStrategies class DirectMatching JSON_ERROR_MESSAGE = 'json file should contain a json object, with array of test files as the values'.freeze def self.load_json(json_file) map = JSON.parse(File.read(json_file)) validate(map) new.tap do |strategy| strategy.map = map end end def self.validate(map) return if map.is_a?(Hash) && map.values.all? { |value| value.is_a?(Array) } raise InvalidMappingFileError, JSON_ERROR_MESSAGE end attr_accessor :map def match(files) Array(files).inject(Set.new) do |result, file| test_files = @map.fetch(file, []) result.merge(test_files) end.to_a end end end end
Version data entries
5 entries across 5 versions & 1 rubygems