Class: ActiveModel::Validations::LessValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/evelpidon_validators/less.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.less?(value, than) ⇒ Boolean



4
5
6
# File 'lib/evelpidon_validators/less.rb', line 4

def self.less?(value, than)
  value.present? and than.present? and value < than
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



8
9
10
11
12
# File 'lib/evelpidon_validators/less.rb', line 8

def validate_each(record, attribute, value)
  unless self.class.less? value, record.send(options[:than]) or (options[:or_equal] && value.eql?(record.send(options[:than])))
    record.errors.add(attribute, :less, options)
  end
end