debian-mirror-gitlab/app/validators/iso8601_date_validator.rb
2023-03-04 22:38:38 +05:30

9 lines
316 B
Ruby

# frozen_string_literal: true
class Iso8601DateValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
Date.iso8601(record.read_attribute_before_type_cast(attribute).to_s)
rescue ArgumentError, TypeError
record.errors.add(attribute, _('must be in ISO 8601 format'))
end
end