Class: LooseChange::Validations::UniquenessValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/loose_change/validations.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



14
15
16
17
# File 'lib/loose_change/validations.rb', line 14

def validate(record)
  record.errors[@options[:property]] << "must be present" unless record.send(@options[:property]) || @options[:allow_nil]
  record.errors[@options[:property]] << "is already taken" if record.send(@options[:property]).present? && duplicate_exists?(record)
end