Class: CpfValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- CpfValidator
- Defined in:
- app/validators/cpf_validator.rb
Constant Summary collapse
- NIL_CPFS =
%w(12345678909 11111111111 22222222222 33333333333 44444444444 55555555555 66666666666 77777777777 88888888888 99999999999 00000000000)
Instance Method Summary collapse
Instance Method Details
#validate(order) ⇒ Object
4 5 6 7 8 9 10 |
# File 'app/validators/cpf_validator.rb', line 4 def validate(order) ship_address_cpf = order.ship_address.try(:cpf) bill_address_cpf = order.bill_address.try(:cpf) order.errors.add(:ship_address, :cpf_invalid) if ship_address_cpf && !valid_cpf?(ship_address_cpf) && Spree::Config[:ship_address_has_cpf] order.errors.add(:bill_address, :cpf_invalid) if bill_address_cpf && !valid_cpf?(bill_address_cpf) end |