Class: Reviewer::History

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = Reviewer.configuration.history_file) ⇒ History

Creates an instance of a YAML::Store-backed history file.

Parameters:

  • file (defaults to: Reviewer.configuration.history_file)

    Reviewer.configuration.history_file [Pathname] the history file to store data



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

#fileObject (readonly)

Returns the value of attribute file.



18
19
20
# File 'lib/reviewer/history.rb', line 18

def file
  @file
end

#storeObject (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

Parameters:

  • group (Symbol)

    the first-level key to use for retrieving the value

  • attribute (Symbol)

    the second-level key to use for retrieving the value

Returns:

  • (Primitive)

    the value being stored



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

Parameters:

  • group (Symbol)

    the first-level key to use for saving the value–frequently a tool name

  • attribute (Symbol)

    the second-level key to use for retrieving the value

  • value (Primitive)

    any value that can be cleanly stored in YAML

Returns:

  • (Primitive)

    the value being stored



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