Class: ActiveModel::Validations::NumberPlateValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/number_plate_validator/active_model.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/number_plate_validator/active_model.rb', line 4

def validate_each(record, attribute, value)
	country = case(options[:country])
						when Proc
							options[:country].call(record)
						when Symbol
							record.send(options[:country])
						else 
							options[:country]
						end

  val = ::NumberPlateValidator.validator(country)

	record.errors.add attribute, (options[:message] || "is not a valid number plate") unless val.is_valid?(value)
end