class UseCaseValidations::Validations::UniquenessValidator

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# 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