class ActiveModel::Validations::CreditCardValidator::ActiveCreditCardBrand

Constants

BRANDS_ALIASES
DEPRECATED_BRANDS

Public Class Methods

new(number) click to toggle source
# File lib/active_validators/active_model/validations/credit_card_validator.rb, line 26
def initialize(number)
  @number = number
end

Public Instance Methods

valid?(*brands) click to toggle source
# File lib/active_validators/active_model/validations/credit_card_validator.rb, line 30
def valid?(*brands)
  deprecated_brands(brands).each do |brand|
    ActiveSupport::Deprecation.warn("support for #{brand} will be removed in future versions, please use #{BRANDS_ALIASES[brand]} instead")
  end
  detector.valid?(*normalize_brands(brands))
end

Private Instance Methods

deprecated_brands(brands) click to toggle source
# File lib/active_validators/active_model/validations/credit_card_validator.rb, line 43
def deprecated_brands(brands)
  DEPRECATED_BRANDS & brands
end
detector() click to toggle source
# File lib/active_validators/active_model/validations/credit_card_validator.rb, line 39
def detector
  CreditCardValidations::Detector.new(@number)
end
normalize_brands(brands = []) click to toggle source
# File lib/active_validators/active_model/validations/credit_card_validator.rb, line 47
def normalize_brands(brands = [])
  brands.uniq.each_with_index do |brand, index|
    brands[index] = BRANDS_ALIASES[brand].present? ? BRANDS_ALIASES[brand] : brand
  end
  brands
end