Sha256: 01aa82c44e55ca15a7588937064364f1257bc5009ad673c341f89df8eaa8610c

Contents?: true

Size: 1.01 KB

Versions: 28

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, &block)
        if !instance.data.is_a?(Integer)
          yield error(instance, 'integer')
          return
        end

        validate_numeric(instance, &block)
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
json_schemer-1.0.3 lib/json_schemer/schema/draft4.rb
json_schemer-1.0.2 lib/json_schemer/schema/draft4.rb
json_schemer-1.0.1 lib/json_schemer/schema/draft4.rb
json_schemer-1.0.0 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.25 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.24 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.23 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.22 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.21 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.20 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.19 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.18 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.17 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.16 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.15 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.14 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.13 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.12 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.11 lib/json_schemer/schema/draft4.rb
json_schemer-0.2.10 lib/json_schemer/schema/draft4.rb