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.
Class Method Summary collapse
-
.reset! ⇒ void
Convenience class method for removing the history file.
Instance Method Summary collapse
-
#get(group, attribute) ⇒ Primitive
Retrieves a stored value from the history file.
-
#initialize(file = Reviewer.configuration.history_file) ⇒ History
constructor
Creates an instance of a YAML::Store-backed history file.
-
#reset! ⇒ void
Removes the existing history file.
-
#set(group, attribute, value) ⇒ Primitive
Saves a value to a given location in the history.
Constructor Details
#initialize(file = Reviewer.configuration.history_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 = Reviewer.configuration.history_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 |
Class Method Details
.reset! ⇒ void
This method returns an undefined value.
Convenience class method for removing the history file.
65 66 67 |
# File 'lib/reviewer/history.rb', line 65 def self.reset! new.reset! end |
Instance Method Details
#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 do |s| s[group].nil? ? nil : s[group][attribute] end end |
#reset! ⇒ 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 reset! return unless File.exist?(file) FileUtils.rm(file) 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 |s| s[group] = {} if s[group].nil? s[group][attribute] = value end end |