Class: Reviewer::History
- Inherits:
-
Object
- Object
- Reviewer::History
- Defined in:
- lib/reviewer/history.rb
Overview
Provides an interface to a local storage resource for persisting data across runs. For example, it enables remembering when prepare commands were run for reviews so they can be run less frequently and thus improve performance.
It also enables remembering seeds across runs. Eventually ‘rvw rerun` could reuse the seeds from the immediately preceding run to more easily facilitate fixing tests that are accidentally order-dependent. Or it could automatically record a list of seeds that led to failures.
Long term, it could serve to record timing details across runs to provide insight to min, max, and means. Those times could then be used for reviewer to make more informed decisions about default behavior to ensure each run remains fast.
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
-
#clear ⇒ void
Removes the existing history file.
-
#get(group, attribute) ⇒ Primitive
Retrieves a stored value from the history file.
-
#initialize(file:) ⇒ History
constructor
Creates an instance of a YAML::Store-backed history file.
-
#set(group, attribute, value) ⇒ Primitive
Saves a value to a given location in the history.
Constructor Details
#initialize(file:) ⇒ History
Creates an instance of a YAML::Store-backed history file
24 25 26 27 |
# File 'lib/reviewer/history.rb', line 24 def initialize(file:) @file = file @store = YAML::Store.new(file) end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
18 19 20 |
# File 'lib/reviewer/history.rb', line 18 def file @file end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
18 19 20 |
# File 'lib/reviewer/history.rb', line 18 def store @store end |
Instance Method Details
#clear ⇒ void
This method returns an undefined value.
Removes the existing history file.
56 57 58 59 60 |
# File 'lib/reviewer/history.rb', line 56 def clear return unless File.exist?(file) FileUtils.rm(file) end |
#get(group, attribute) ⇒ Primitive
Retrieves a stored value from the history file
47 48 49 50 51 |
# File 'lib/reviewer/history.rb', line 47 def get(group, attribute) store.transaction(true) do store[group]&.[](attribute) end end |
#set(group, attribute, value) ⇒ Primitive
Saves a value to a given location in the history
35 36 37 38 39 40 |
# File 'lib/reviewer/history.rb', line 35 def set(group, attribute, value) store.transaction do store[group] ||= {} store[group][attribute] = value end end |