Class: UseCaseValidations::Validations::UniquenessValidator

Inherits:
EachValidator show all
Defined in:
lib/usecasing_validations/validations/uniqueness.rb

Instance Attribute Summary

Attributes inherited from EachValidator

#attributes

Attributes inherited from UseCaseValidations::Validator

#base, #options

Instance Method Summary collapse

Methods inherited from EachValidator

#check_validity!, #initialize, #validate

Methods inherited from UseCaseValidations::Validator

#initialize, #validate

Constructor Details

This class inherits a constructor from UseCaseValidations::EachValidator

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/usecasing_validations/validations/uniqueness.rb', line 5

def validate_each(record, attribute, value)

  return nil unless scope_method(record)

  records.each do |other_record|
    next if record == other_record || Helpers._marked_for_destruction?(other_record) || !scope_method(other_record)

    if similar_objects?(record, other_record, attribute)
      record.errors.add(attribute, :taken, options)
      break
    end
  end

end