Class: TrackingNumberValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- TrackingNumberValidator
- Defined in:
- lib/tracking_number/active_model_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'lib/tracking_number/active_model_validator.rb', line 2 def validate_each(record, attribute, value) return unless value.present? if [:exception] == value || [:except] == value # magic valid value (an exception that says "not really shipped" or something) elsif TrackingNumber.new(value).valid? # looks good to me else record.errors[attribute] << [:message] || 'is not a valid tracking number' end end |