mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 00:42:04 +02:00
Introduce 'optional' validator to epp controllers
This commit is contained in:
parent
3a529135ea
commit
e6b36c409d
6 changed files with 96 additions and 16 deletions
30
app/validators/date_time_iso8601_validator.rb
Normal file
30
app/validators/date_time_iso8601_validator.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
class DateTimeIso8601Validator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
return if self.class.validate(value)
|
||||
record.errors[attribute] << (options[:message] || I18n.t('unknown_expiry_absolute_pattern'))
|
||||
end
|
||||
|
||||
class << self
|
||||
def validate(value)
|
||||
return true if value.empty?
|
||||
|
||||
begin
|
||||
DateTime.parse(value)
|
||||
rescue => _e
|
||||
return false
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def validate_epp(obj, value)
|
||||
return if validate(value)
|
||||
|
||||
{
|
||||
code: '2005',
|
||||
msg: I18n.t(:unknown_expiry_absolute_pattern),
|
||||
value: { obj: obj, val: value }
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue