Sha256: 4b2dc2edec92b6e730b82c488af24656038fecc121857e5a062f4d41f4047723

Contents?: true

Size: 839 Bytes

Versions: 3

Compression:

Stored size: 839 Bytes

Contents

# encoding: utf-8
module Mongoid
  module Validations

    # Adds localization support to validations.
    module Localizable

      # Validates each for localized fields.
      #
      # @example Validate localized fields.
      #   validator.validate_each(model, :name, "value")
      #
      # @param [ Document ] document The document.
      # @param [ Symbol, String ] attribute The attribute to validate.
      # @param [ Object ] value The attribute value.
      #
      # @since 2.4.2
      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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-3.1.7 lib/mongoid/validations/localizable.rb
mongoid-3.1.6 lib/mongoid/validations/localizable.rb
mongoid-3.1.5 lib/mongoid/validations/localizable.rb