Class: DiffTest::FileHashComputer

Inherits:
Object
  • Object
show all
Defined in:
lib/diff_test/file_hash_computer.rb

Class Method Summary collapse

Class Method Details

.compute(file_path) ⇒ Object

Save hashesh in a global cache. If available use it, otherwise compute it.



7
8
9
10
11
12
13
14
15
# File 'lib/diff_test/file_hash_computer.rb', line 7

def self.compute(file_path)
  return @cache[file_path] if @cache&.key?(file_path)

  content = File.read(file_path)
  content = DiffTest::Integrations::RailsJs::Annotator.unannotate(content)

  @cache ||= {}
  @cache[file_path] = XXhash.xxh32(content).to_s
end

.compute_relative(file_path) ⇒ Object



17
18
19
# File 'lib/diff_test/file_hash_computer.rb', line 17

def self.compute_relative(file_path)
  self.compute(DiffTest::Helper.absolute_path_from_project_root(file_path))
end