1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
# frozen_string_literal: true
module JSONSchemer
module Draft202012
module Vocab
module FormatAssertion
class Format < Keyword
def error(formatted_instance_location:, **)
"value at #{formatted_instance_location} does not match format: #{value}"
end
def parse
root.format && root.fetch_format(value) { raise UnknownFormat, value }
end
def validate(instance, instance_location, keyword_location, _context)
valid = parsed == false || parsed.call(instance, value)
result(instance, instance_location, keyword_location, valid, :annotation => value)
end
end
end
end
end
end
|