Class: IncrementalFixpoint

Inherits:
Fixpoint show all
Defined in:
lib/incremental_fixpoint.rb

Overview

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.

Constant Summary collapse

PARENT_YAML_KEY =
'++parent_fixpoint++'

Constants inherited from Fixpoint

Fixpoint::FIXPOINT_FOLDER, Fixpoint::TABLES_TO_SKIP

Instance Attribute Summary collapse

Attributes inherited from Fixpoint

#records_in_tables

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Fixpoint

exists?, fixpoint_path, #load_into_database, #records_for_table, remove, reset_pk_sequences!, #save_to_file, #table_names

Constructor Details

#initialize(changes_in_tables, parent_fixname = nil) ⇒ IncrementalFixpoint

Returns a new instance of IncrementalFixpoint.



15
16
17
18
19
20
21
22
23
24
# 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

Instance Attribute Details

#changes_in_tablesObject (readonly)

only the difference to the parent (in tables)



13
14
15
# File 'lib/incremental_fixpoint.rb', line 13

def changes_in_tables
  @changes_in_tables
end

Class Method Details

.from_database(parent_fixname = nil, conn) ⇒ Object

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



36
37
38
39
40
41
42
# 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) ⇒ Object

Raises:



26
27
28
29
30
31
32
33
# 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