Class: IsraeliIdValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- IsraeliIdValidator
- Defined in:
- lib/israeli/active_model/israeli_id_validator.rb
Overview
Validates that an attribute is a valid Israeli ID number (Mispar Zehut).
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/israeli/active_model/israeli_id_validator.rb', line 17 def validate_each(record, attribute, value) return if value.blank? && [:allow_blank] return if value.nil? && [:allow_nil] return if Israeli::Validators::Id.valid?(value) reason = Israeli::Validators::Id.invalid_reason(value) record.errors.add( attribute, [:message] || :invalid, reason: reason ) end |