Class: Subvalid::Validators::NumericalityValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/subvalid/validators/numericality_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
# File 'lib/subvalid/validators/numericality_validator.rb', line 4

def self.validate(object, validation_result=ValidationResult.new, *args)
  args = args.to_h
  args.each do |operator, value|
    case operator
      when :greater_than_or_equal_to
        validation_result.add_error("must be greater than or equal to #{value}" ) unless object >= value
      # TODO ALL the other operators from http://guides.rubyonrails.org/active_record_validations.html#numericality
      else
        raise "don't know what to do with operator=#{operator}"
    end
  end
end