Sha256: 0bee6d821746f0a031ba46785f3a4f6bff1b59aac1243f483c6caada84c2affb
Contents?: true
Size: 874 Bytes
Versions: 6
Compression:
Stored size: 874 Bytes
Contents
require 'json-schema/attributes/format' module JSON class Schema class DateFormat < FormatAttribute REGEXP = /\A\d{4}-\d{2}-\d{2}\z/ def self.validate(current_schema, data, fragments, processor, validator, options = {}) if data.is_a?(String) error_message = "The property '#{build_fragment(fragments)}' must be a date in the format of YYYY-MM-DD" if REGEXP.match(data) begin Date.parse(data) rescue ArgumentError => e raise e unless e.message == 'invalid date' validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) end else validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) end end end end end end
Version data entries
6 entries across 5 versions & 3 rubygems