Class: BazaModels::Validators::LengthValidator

Inherits:
BaseValidator show all
Defined in:
lib/baza_models/validators/length_validator.rb

Instance Attribute Summary

Attributes inherited from BaseValidator

#args, #attribute_name

Instance Method Summary collapse

Methods inherited from BaseValidator

#fire?, #initialize

Constructor Details

This class inherits a constructor from BazaModels::Validators::BaseValidator

Instance Method Details

#validate(model, value) ⇒ Object



2
3
4
5
# File 'lib/baza_models/validators/length_validator.rb', line 2

def validate(model, value)
  model.errors.add(attribute_name, "is too long") if max_length && value.to_s.length > max_length
  model.errors.add(attribute_name, "is too short") if min_length && value.to_s.length < min_length
end