Class: Dynamoid::Validations::UniquenessValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/activity_notification/orm/dynamoid/extension.rb

Overview

Validates whether or not a field is unique against the records in the database.

Instance Method Summary collapse

Instance Method Details

#validate_each(document, attribute, value) ⇒ Object

Validate the document for uniqueness violations.

Parameters:

  • document (Document)

    The document to validate.

  • attribute (Symbol)

    The name of the attribute.

  • value (Object)

    The value of the object.



98
99
100
101
102
103
104
# File 'lib/activity_notification/orm/dynamoid/extension.rb', line 98

def validate_each(document, attribute, value)
  return unless validation_required?(document, attribute)
  if not_unique?(document, attribute, value)
    error_options = options.except(:scope).merge(value: value)
    document.errors.add(attribute, :taken, **error_options)
  end
end