Sha256: c082a4bc573d42222e56a50c06b639ea667dd2225c81c765567d6aab0faca429
Contents?: true
Size: 460 Bytes
Versions: 7
Compression:
Stored size: 460 Bytes
Contents
module ActiveModel module Validations class CreditCardNumberValidator < EachValidator def validate_each(record, attribute, value) brands = options.fetch(:brands, :any) record.errors.add(attribute) unless credit_card_valid?(value, brands == :any ? [] : Array.wrap(brands) ) end def credit_card_valid?(number, brands = []) CreditCardValidations::Detector.new(number).valid?(*brands) end end end end
Version data entries
7 entries across 7 versions & 1 rubygems