25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/canon/comparison/json_comparator.rb', line 25
def equivalent?(json1, json2, opts = {})
opts = DEFAULT_OPTS.merge(opts)
match_opts_hash = MatchOptions::Json.resolve(
format: :json,
match_profile: opts[:match_profile],
match: opts[:match],
preprocessing: opts[:preprocessing],
global_profile: opts[:global_profile],
global_options: opts[:global_options],
)
opts[:match_opts] = match_opts_hash
obj1 = parse_json(json1)
obj2 = parse_json(json2)
differences = []
result = RubyObjectComparator.compare_objects(obj1, obj2, opts,
differences, "")
if opts[:verbose]
json_str1 = obj1.is_a?(String) ? obj1 : JSON.pretty_generate(obj1)
json_str2 = obj2.is_a?(String) ? obj2 : JSON.pretty_generate(obj2)
ComparisonResult.new(
differences: differences,
preprocessed_strings: [json_str1, json_str2],
format: :json,
match_options: match_opts_hash,
)
else
result == Comparison::EQUIVALENT
end
end
|