Class: CnsBrazil::CnsValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/cns_brazil/cns_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/cns_brazil/cns_validator.rb', line 6

def validate_each(record, attribute, value)
  return true if options[:allow_blank] && value.blank?

  cns = CnsBrazil::Cns.new(value: value)

  record.errors.add(attribute, (options[:message] || 'is not an cns')) unless cns.valid?
end