Class: TestMap::Cache
- Inherits:
-
Object
- Object
- TestMap::Cache
- Defined in:
- lib/test_map/cache.rb
Overview
Cache tracks file checksums to skip unchanged tests.
Constant Summary collapse
- GLOBAL_FILES =
%w[Gemfile.lock .ruby-version].freeze
Instance Method Summary collapse
- #fresh?(test_file) ⇒ Boolean
-
#initialize(cache_file, map_file, root: Dir.pwd) ⇒ Cache
constructor
A new instance of Cache.
- #write(results) ⇒ Object
Constructor Details
#initialize(cache_file, map_file, root: Dir.pwd) ⇒ Cache
Returns a new instance of Cache.
11 12 13 14 15 16 17 18 |
# File 'lib/test_map/cache.rb', line 11 def initialize(cache_file, map_file, root: Dir.pwd) @cache_file = cache_file @map_file = map_file @root = root @global_files_changed = nil @current_checksums = {} @file_exists_cache = {} end |
Instance Method Details
#fresh?(test_file) ⇒ Boolean
20 21 22 23 24 25 26 |
# File 'lib/test_map/cache.rb', line 20 def fresh?(test_file) return false unless cached_checksums return false if global_files_changed? files_to_check = [test_file].concat(source_files_for(test_file)) files_to_check.all? { |f| file_exist?(f) && current_checksum(f) == cached_checksums[f] } end |
#write(results) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/test_map/cache.rb', line 28 def write(results) all_files = collect_tracked_files(results) checksums = all_files.each_with_object({}) do |file, hash| hash[file] = current_checksum(file) if file_exist?(file) end File.write(@cache_file, checksums.sort.to_h.to_yaml) end |