Class: Evilution::Cache Private

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/cache.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

DEFAULT_DIR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"tmp/evilution_cache"

Instance Method Summary collapse

Constructor Details

#initialize(cache_dir: DEFAULT_DIR) ⇒ Cache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Cache.



10
11
12
# File 'lib/evilution/cache.rb', line 10

def initialize(cache_dir: DEFAULT_DIR)
  @cache_dir = cache_dir
end

Instance Method Details

#clearObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
# File 'lib/evilution/cache.rb', line 46

def clear
  FileUtils.rm_rf(@cache_dir)
end

#fetch(mutation) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/evilution/cache.rb', line 14

def fetch(mutation)
  return nil if mutation.original_source.nil?

  file_key = file_key(mutation)
  entry_key = entry_key(mutation)
  data = read_file(file_key)
  return nil unless data

  entry = data[entry_key]
  return nil unless entry.is_a?(Hash) && entry["status"].is_a?(String)

  { status: entry["status"].to_sym, duration: entry["duration"],
    killing_test: entry["killing_test"], test_command: entry["test_command"] }
end

#store(mutation, result_data) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/evilution/cache.rb', line 29

def store(mutation, result_data)
  return if mutation.original_source.nil?

  file_key = file_key(mutation)
  entry_key = entry_key(mutation)
  data = read_file(file_key) || {}

  data[entry_key] = {
    "status" => result_data[:status].to_s,
    "duration" => result_data[:duration],
    "killing_test" => result_data[:killing_test],
    "test_command" => result_data[:test_command]
  }

  write_file(file_key, data)
end