Class: Ea::Diff::Comparator

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/diff/comparator.rb

Overview

Compares two Ea::Qea::Database instances and produces a list of structural changes. Identity is keyed by primary-key value within each collection; renaming surfaces as :removed + :added unless the name change happens with the same PK (then it's :renamed).

OCP: new entity types are added by registering a comparator entry in COLLECTIONS, not by modifying this class.

Constant Summary collapse

COLLECTIONS =

Each entry maps a collection name to the attribute used as the human-readable label. Add new collections here without touching the diff algorithm.

{
  packages: :name,
  objects: :name,
  attributes: :name,
  operations: :name,
  connectors: :name,
  diagrams: :name
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(old_db, new_db) ⇒ Comparator

Returns a new instance of Comparator.



27
28
29
30
31
32
# File 'lib/ea/diff/comparator.rb', line 27

def initialize(old_db, new_db)
  @old_db = old_db
  @new_db = new_db
  @differences = []
  compare_all
end

Instance Attribute Details

#differencesObject (readonly)

Returns the value of attribute differences.



13
14
15
# File 'lib/ea/diff/comparator.rb', line 13

def differences
  @differences
end

#new_dbObject (readonly)

Returns the value of attribute new_db.



13
14
15
# File 'lib/ea/diff/comparator.rb', line 13

def new_db
  @new_db
end

#old_dbObject (readonly)

Returns the value of attribute old_db.



13
14
15
# File 'lib/ea/diff/comparator.rb', line 13

def old_db
  @old_db
end

Instance Method Details

#identical?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/ea/diff/comparator.rb', line 34

def identical?
  @differences.empty?
end