class IncrementalFixpoint

Enhances Fixpoint to only save incremental changes.

A fixpoint can be saved fully, where all records are saved to the file or one can give a parent fixpoint. When doing so, only the difference (aka. changes) to the parent is saved in the file. Yet, if a record does not change parent an empty hash is saved. This is done, so removals from the database can be tracked.

LIMITATIONS Assume you remove a record at the end of a table and then add another one. Then the fixpoint diff will complain that an entry has changed instead of noticing the addition/removal.

Constants

PARENT_YAML_KEY

Attributes

changes_in_tables[R]

Public Class Methods

from_database(parent_fixname=nil, conn) click to toggle source

Creates a Fixpoint from the database contents. Empty tables are skipped.

Calls superclass method Fixpoint::from_database
# File lib/incremental_fixpoint.rb, line 36
def self.from_database(parent_fixname=nil, conn)
  return super(conn) if parent_fixname.nil?

  parent = from_file(parent_fixname)
  changes_in_tables = FixpointDiff.extract_changes(parent.records_in_tables, read_database_records(conn))
  new(changes_in_tables, parent_fixname)
end
from_file(fixname) click to toggle source
# File lib/incremental_fixpoint.rb, line 26
def self.from_file(fixname)
  raise Fixpoint::Error, "The requested fixpoint (\"#{fixname}\") could not be found. Re-run the test which stores the fixpoint." unless exists?(fixname)

  file_path = fixpoint_path(fixname)
  changes_in_tables = YAML.load_file(file_path)
  parent_fixname = changes_in_tables.delete(PARENT_YAML_KEY)
  new(changes_in_tables, parent_fixname)
end
new(changes_in_tables, parent_fixname=nil) click to toggle source
Calls superclass method Fixpoint::new
# File lib/incremental_fixpoint.rb, line 15
def initialize(changes_in_tables, parent_fixname=nil)
  @parent_fixname = parent_fixname
  @changes_in_tables = changes_in_tables
  if parent_fixname.nil?
    super(changes_in_tables)
  else
    parent = self.class.from_file(parent_fixname)
    super(FixpointDiff.apply_changes(parent.records_in_tables, @changes_in_tables))
  end
end

Protected Instance Methods

contents_for_file() click to toggle source
# File lib/incremental_fixpoint.rb, line 46
def contents_for_file
  file_contents = @changes_in_tables.dup
  file_contents[PARENT_YAML_KEY] = @parent_fixname unless @parent_fixname.nil?
  return YAML.dump(file_contents)
end