Class: SuperModel::Validations::UniquenessValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- SuperModel::Validations::UniquenessValidator
- Defined in:
- lib/supermodel/validations/uniqueness.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
Instance Attribute Details
#klass ⇒ Object (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 => [:message]) end |