Allow absence of name servers

#267
This commit is contained in:
Artur Beljajev 2016-12-28 15:01:32 +02:00
parent 3c4cba93f4
commit d39d3766b2
9 changed files with 484 additions and 11 deletions

View file

@ -0,0 +1,12 @@
class DomainNameserverValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return true if !Domain.nameserver_required? && value.empty?
min, max = options[:min].call, options[:max].call
values = value.reject(&:marked_for_destruction?)
return if values.size.between?(min, max)
association = options[:association] || attribute
record.errors.add(association, :out_of_range, { min: min, max: max })
end
end