Class: ActiveModel::Validations::DifferentValidator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.different?(value, than) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.different?(value, than)
  not value.eql? than
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



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

def validate_each(record, attribute, value)
  unless self.class.different? value, record.send(options[:than])
    record.errors.add(attribute, :different, options)
  end
end