Sha256: 028ee154dc9f023a33830ff7b9e457bab2c996e757619c1e884b5e37bf5eb565

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module JSONSchemer
  module Schema
    class Draft4 < Base
      ID_KEYWORD = 'id'
      SUPPORTED_FORMATS = Set[
        'date-time',
        'email',
        'hostname',
        'ipv4',
        'ipv6',
        'uri',
        'regex'
      ].freeze

    private

      def id_keyword
        ID_KEYWORD
      end

      def supported_format?(format)
        SUPPORTED_FORMATS.include?(format)
      end

      def validate_exclusive_maximum(instance, exclusive_maximum, maximum)
        yield error(instance, 'exclusiveMaximum') if exclusive_maximum && instance.data >= maximum
      end

      def validate_exclusive_minimum(instance, exclusive_minimum, minimum)
        yield error(instance, 'exclusiveMinimum') if exclusive_minimum && instance.data <= minimum
      end

      def validate_integer(instance)
        if !instance.data.is_a?(Integer)
          yield error(instance, 'integer')
          return
        end

        validate_numeric(instance, &Proc.new)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
json_schemer-0.1.10 lib/json_schemer/schema/draft4.rb
json_schemer-0.1.9 lib/json_schemer/schema/draft4.rb
json_schemer-0.1.8 lib/json_schemer/schema/draft4.rb
json_schemer-0.1.7 lib/json_schemer/schema/draft4.rb
json_schemer-0.1.6 lib/json_schemer/schema/draft4.rb