Module: Mongoid::Validatable::Localizable

Included in:
FormatValidator, LengthValidator
Defined in:
build/mongoid-master/lib/mongoid/validatable/localizable.rb

Overview

Adds localization support to validations.

Instance Method Summary collapse

Instance Method Details

#validate_each(document, attribute, value) ⇒ Object

Validates each for localized fields.

Examples:

Validate localized fields.

validator.validate_each(model, :name, "value")

Parameters:

  • document (Document)

    The document.

  • attribute (Symbol, String)

    The attribute to validate.

  • value (Object)

    The attribute value.

Since:

  • 2.4.2



20
21
22
23
24
25
26
27
28
29
# File 'build/mongoid-master/lib/mongoid/validatable/localizable.rb', line 20

def validate_each(document, attribute, value)
  field = document.fields[document.database_field_name(attribute)]
  if field.try(:localized?) && !value.blank?
    value.values.each do |_value|
      super(document, attribute, _value)
    end
  else
    super
  end
end