Class: Subvalid::Validators::LengthValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/subvalid/validators/length_validator.rb

Class Method Summary collapse

Class Method Details

.validate(object, validation_result = ValidationResult.new, *args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/subvalid/validators/length_validator.rb', line 4

def self.validate(object, validation_result=ValidationResult.new, *args)
  return unless object
  args = args.to_h
  args.each do |operator, value|
    case operator
    when :maximum
      validation_result.add_error("is too long, maximum is #{value}") if object.size > value
      # TODO ALL the other operators from http://guides.rubyonrails.org/active_record_validations.html#length
    else
      raise "don't know what to do with operator=#{operator}"
    end
  end
end