class Reorm::MinimumLengthValidator

Public Class Methods

new(length, *field) click to toggle source
Calls superclass method
# File lib/reorm/validators/minimum_length_validator.rb, line 7
def initialize(length, *field)
  super("is too short (minimum length is #{length} characters).", *field)
  @length = length
end

Public Instance Methods

validate(object) click to toggle source
# File lib/reorm/validators/minimum_length_validator.rb, line 12
def validate(object)
  value = field.value(object)
  if [nil, ""].include?(value) || value.to_s.length < @length
    object.errors.add field.to_s, message
  end
end