class MinMaxValidator
Public Instance Methods
validate(record)
click to toggle source
# File lib/min_max_validator.rb, line 7 def validate(record) min = record.send options[:fields][:min] max = record.send options[:fields][:max] unless valid_max_value?(min: min, max: max) record.errors.add(options[:fields][:max], options[:fields][:msg]) end end
Private Instance Methods
valid_max_value?(min: 0, max: nil)
click to toggle source
# File lib/min_max_validator.rb, line 18 def valid_max_value?(min: 0, max: nil) if min.present? && max.present? max >= min else true end end