Class: ActiveModel::Validations::LuhnAlgorithmValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/luhn_algorithm/validator.rb

Overview

active model validator for Luhn Algorithm

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



7
8
9
10
# File 'lib/luhn_algorithm/validator.rb', line 7

def validate_each(record, attribute, value)
  return if LuhnAlgorithm.valid?(value)
  record.errors.add(attribute, options[:message] || :invalid)
end