Sha256: 4c6b517b3ab35bd916bbad69572dcd818c364dc0df8ae61d173c206da37b5c31

Contents?: true

Size: 823 Bytes

Versions: 9

Compression:

Stored size: 823 Bytes

Contents

# frozen_string_literal: true

module Mongoid
  module Validatable

    # 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.
      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

9 entries across 9 versions & 1 rubygems

Version Path
mongoid-7.5.4 lib/mongoid/validatable/localizable.rb
mongoid-7.5.3 lib/mongoid/validatable/localizable.rb
mongoid-7.5.2 lib/mongoid/validatable/localizable.rb
mongoid-7.5.1 lib/mongoid/validatable/localizable.rb
mongoid-7.4.3 lib/mongoid/validatable/localizable.rb
mongoid-8.0.1 lib/mongoid/validatable/localizable.rb
mongoid-7.5.0 lib/mongoid/validatable/localizable.rb
mongoid-7.4.1 lib/mongoid/validatable/localizable.rb
mongoid-7.4.0 lib/mongoid/validatable/localizable.rb