Class: SexyValidations::Validators::Length

Inherits:
Object
  • Object
show all
Defined in:
lib/sexy_validations/validators/length.rb

Class Method Summary collapse

Class Method Details

.validate(model, attribute, value, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sexy_validations/validators/length.rb', line 5

def self.validate(model, attribute, value, options)
  return unless value

  unless options.is_a?(Hash)
    options = {
      :within => options,
    }
  end

  min = options[:within].min
  if value.length < min
    model.errors.add(attribute, "zu kurz (mindestens #{min} Zeichen)")
  end

  max = options[:within].max
  if value.length > max
    model.errors.add(attribute, "zu lang (maximal #{max} Zeichen)")
  end
end