Module: Philiprehberger::TomlKit::Diff

Defined in:
lib/philiprehberger/toml_kit/diff.rb

Overview

Compares two TOML documents (as hashes) and reports differences.

Returns a structured diff with:

- :added    -> keys present only in the right document
- :removed  -> keys present only in the left document
- :changed  -> keys present in both but with different values

Defined Under Namespace

Classes: Change

Class Method Summary collapse

Class Method Details

.additions(left, right) ⇒ Array<Change>

Return only additions (keys in right but not left).

Parameters:

  • left (Hash)
  • right (Hash)

Returns:



31
32
33
# File 'lib/philiprehberger/toml_kit/diff.rb', line 31

def self.additions(left, right)
  diff(left, right).select { |c| c.type == :added }
end

.changes(left, right) ⇒ Array<Change>

Return only changes (keys in both with different values).

Parameters:

  • left (Hash)
  • right (Hash)

Returns:



49
50
51
# File 'lib/philiprehberger/toml_kit/diff.rb', line 49

def self.changes(left, right)
  diff(left, right).select { |c| c.type == :changed }
end

.diff(left, right) ⇒ Array<Change>

Compare two parsed TOML hashes.

Parameters:

  • left (Hash)

    first document

  • right (Hash)

    second document

Returns:

  • (Array<Change>)

    list of differences



20
21
22
23
24
# File 'lib/philiprehberger/toml_kit/diff.rb', line 20

def self.diff(left, right)
  changes = []
  compare(left, right, [], changes)
  changes
end

.identical?(left, right) ⇒ Boolean

Check if two documents are identical.

Parameters:

  • left (Hash)
  • right (Hash)

Returns:

  • (Boolean)


58
59
60
# File 'lib/philiprehberger/toml_kit/diff.rb', line 58

def self.identical?(left, right)
  diff(left, right).empty?
end

.removals(left, right) ⇒ Array<Change>

Return only removals (keys in left but not right).

Parameters:

  • left (Hash)
  • right (Hash)

Returns:



40
41
42
# File 'lib/philiprehberger/toml_kit/diff.rb', line 40

def self.removals(left, right)
  diff(left, right).select { |c| c.type == :removed }
end