Class: PhonyPlausibleValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- PhonyPlausibleValidator
- Defined in:
- lib/phony_attribute/phony_plausible_validator.rb
Overview
global namespace so you can use the rails 3 “validate :field, phony_plausible: [options]”
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/phony_attribute/phony_plausible_validator.rb', line 3 def validate_each(record, attribute, value) return if value.blank? pn = PhonyAttribute::PhoneNumber(value) return if pn.nil? if !pn.valid? record.errors.add(attribute, [:message] || :invalid) else record.errors.add(attribute, 'is a blocked number') if pn.blocked? && ![:allow_blocked] record.errors.add(attribute, :too_short, :count => pn.number.length) if [:minimum_length] && pn.number.length < [:minimum_length] end end |