Class: Evilution::Cache
- Inherits:
-
Object
- Object
- Evilution::Cache
- Defined in:
- lib/evilution/cache.rb
Constant Summary collapse
- DEFAULT_DIR =
"tmp/evilution_cache"
Instance Method Summary collapse
- #clear ⇒ Object
- #fetch(mutation) ⇒ Object
-
#initialize(cache_dir: DEFAULT_DIR) ⇒ Cache
constructor
A new instance of Cache.
- #store(mutation, result_data) ⇒ Object
Constructor Details
#initialize(cache_dir: DEFAULT_DIR) ⇒ Cache
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
#clear ⇒ Object
44 45 46 |
# File 'lib/evilution/cache.rb', line 44 def clear FileUtils.rm_rf(@cache_dir) end |
#fetch(mutation) ⇒ Object
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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/evilution/cache.rb', line 29 def store(mutation, result_data) 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 |