6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'app/services/completion_kit/checks/json_path_equals.rb', line 6
def call(target, config)
parsed = JSON.parse(target.to_s)
value = dig(parsed, config["json_path"].to_s)
if value.equal?(MISSING)
Result.new(passed: false, detail: "path #{config["json_path"]} not found")
elsif value == config["expected"]
Result.new(passed: true, detail: "#{config["json_path"]} == #{config["expected"].inspect}")
else
Result.new(passed: false, detail: "#{config["json_path"]} was #{value.inspect}, expected #{config["expected"].inspect}")
end
rescue JSON::ParserError
Result.new(passed: false, detail: "not valid JSON")
end
|