Class: ActiveModel::Validations::CreditCardNumberValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/active_model/credit_card_number_validator.rb

Instance Method Summary collapse

Instance Method Details

#credit_card_valid?(number, brands = []) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/active_model/credit_card_number_validator.rb', line 49

def credit_card_valid?(number, brands = [])
  CreditCardValidations::Detector.new(number).valid?(*brands)
end

#validate_each(record, attribute, value) ⇒ Object



45
46
47
# File 'lib/active_model/credit_card_number_validator.rb', line 45

def validate_each(record, attribute, value)
  record.errors.add(attribute, options[:message] || :invalid) unless credit_card_valid?(value, extract_brands(record, options))
end