Sha256: 6a6596c176fbd3ae73306aa5a46b88cd3f72e4008892a2a93b8f0a0c73ace4a4
Contents?: true
Size: 936 Bytes
Versions: 2
Compression:
Stored size: 936 Bytes
Contents
module ActiveModel module Validations class CpfValidator < EachValidator def validate_each(record, attribute, value) return if value.blank? && options[:allow_blank] return if value.nil? && options[:allow_nil] return if CPF.valid?(value) record.errors.add(attribute, :invalid_cpf, message: options[:message], value: value ) end end module ClassMethods # Validates whether or not the specified CPF is valid. # # class User < ActiveRecord::Base # validates_cpf_format_of :document # end # def validates_cpf_format_of(*attr_names) require "cpf" validates_with CpfValidator, _merge_attributes(attr_names) rescue LoadError fail "cpf_cnpj is not part of the bundle. Add it to Gemfile." end alias_method :validates_cpf, :validates_cpf_format_of end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
validators-2.8.1 | lib/validators/validates_cpf_format_of.rb |
validators-2.8.0 | lib/validators/validates_cpf_format_of.rb |