File: format_assertion.rb

package info (click to toggle)
ruby-json-schemer 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 552 kB
  • sloc: ruby: 7,449; sh: 4; makefile: 4
file content (23 lines) | stat: -rw-r--r-- 717 bytes parent folder | download
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