Class: ActiveModel::Validations::GreaterValidator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.greater?(value, than) ⇒ Boolean



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

def self.greater?(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/greater.rb', line 8

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