Class: Json::Schema::Diff::Comparer

Inherits:
Object
  • Object
show all
Defined in:
lib/json/schema/diff/comparer.rb

Overview

Compares two JSON objects using schema guidance to detect changes

This class performs recursive comparison of JSON structures, using schema information to provide context and handle special cases like read-only fields.

Instance Method Summary collapse

Constructor Details

#initialize(schema_parser, ignore_fields = []) ⇒ Comparer

Initialize a new Comparer

Parameters:

  • schema_parser (SchemaParser)

    Parser for the JSON Schema

  • ignore_fields (Array<String|Regexp>) (defaults to: [])

    List of field paths and patterns to ignore during comparison



15
16
17
18
# File 'lib/json/schema/diff/comparer.rb', line 15

def initialize(schema_parser, ignore_fields = [])
  @schema_parser = schema_parser
  @ignore_fields = ignore_fields
end

Instance Method Details

#compare(old_json, new_json) ⇒ Array<Hash>

Compares two JSON objects and returns a list of changes

Parameters:

  • old_json (Object)

    The original JSON data

  • new_json (Object)

    The new JSON data to compare against

Returns:

  • (Array<Hash>)

    Array of change objects with metadata



25
26
27
28
29
# File 'lib/json/schema/diff/comparer.rb', line 25

def compare(old_json, new_json)
  changes = []
  compare_recursive(old_json, new_json, "", changes)
  changes
end