mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 18:29:40 +02:00
9 lines
317 B
Ruby
9 lines
317 B
Ruby
class DurationIso8601Validator < ActiveModel::EachValidator
|
|
def validate_each(record, attribute, value)
|
|
return unless value.present?
|
|
|
|
ISO8601::Duration.new(value)
|
|
rescue => _e
|
|
record.errors[attribute] << (options[:message] || record.errors.generate_message(attribute, :unknown_pattern))
|
|
end
|
|
end
|