Sha256: 2076788313c10030291e81ee29136476e5fd4ef6e3c1d1b6fb0d3562d77b1b1b
Contents?: true
Size: 1.59 KB
Versions: 5
Compression:
Stored size: 1.59 KB
Contents
# frozen_string_literal: true module Meta module JsonSchema module Validators @validators = { validate: proc { |value, p| next if value.nil? p.call(value) }, required: proc { |value, options, full_options| next if options == false full_options ||= {} options = {} if options == true raise JsonSchema::ValidationError, I18n.t(:'json_schema.errors.required') if value.nil? if full_options[:type] == 'string' && (!options[:allow_empty]) && value.empty? raise JsonSchema::ValidationError, I18n.t(:'json_schema.errors.required') end if full_options[:type] == 'array' && (options[:allow_empty] == false) && value.empty? raise JsonSchema::ValidationError, I18n.t(:'json_schema.errors.required') end }, format: proc { |value, format| next if value.nil? raise JsonSchema::ValidationError, I18n.t(:'json_schema.errors.format') unless value =~ format }, allowable: proc { |value, allowable_values| next if value.nil? raise JsonSchema::ValidationError, I18n.t(:'json_schema.errors.allowable', allowable_values: allowable_values) unless allowable_values.include?(value) } } class << self def [](key) @validators[key] end def []=(key, validator) @validators[key] = validator end def delete(key) @validators.delete(key) end def keys @validators.keys end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems