Class: SuperModel::Validations::UniquenessValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/supermodel/validations/uniqueness.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/supermodel/validations/uniqueness.rb', line 4

def klass
  @klass
end

Instance Method Details

#setup(klass) ⇒ Object



12
13
14
# File 'lib/supermodel/validations/uniqueness.rb', line 12

def setup(klass)
  @klass = klass
end

#validate_each(record, attribute, value) ⇒ Object



6
7
8
9
10
# File 'lib/supermodel/validations/uniqueness.rb', line 6

def validate_each(record, attribute, value)
  alternate = klass.find_by_attribute(attribute, value)
  return unless alternate
  record.errors.add(attribute, "must be unique", :default => options[:message])
end