Sha256: 2bc09ca57577fa66686dab522785b8d233b5dd2fb38b84cc0d501d93610b4045

Contents?: true

Size: 870 Bytes

Versions: 27

Compression:

Stored size: 870 Bytes

Contents

# frozen_string_literal: true
# encoding: utf-8

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

27 entries across 27 versions & 2 rubygems

Version Path
mongoid-7.3.5 lib/mongoid/validatable/localizable.rb
mongoid-7.3.4 lib/mongoid/validatable/localizable.rb
mongoid-7.1.11 lib/mongoid/validatable/localizable.rb
mongoid-7.2.6 lib/mongoid/validatable/localizable.rb
mongoid-7.3.3 lib/mongoid/validatable/localizable.rb
mongoid-7.3.2 lib/mongoid/validatable/localizable.rb
mongoid-7.2.5 lib/mongoid/validatable/localizable.rb
mongoid-7.1.10 lib/mongoid/validatable/localizable.rb
mongoid-7.1.9 lib/mongoid/validatable/localizable.rb
mongoid-7.2.4 lib/mongoid/validatable/localizable.rb
mongoid-7.3.1 lib/mongoid/validatable/localizable.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/lib/mongoid/validatable/localizable.rb
mongoid-7.3.0 lib/mongoid/validatable/localizable.rb
mongoid-7.2.3 lib/mongoid/validatable/localizable.rb
mongoid-7.1.8 lib/mongoid/validatable/localizable.rb
mongoid-7.2.2 lib/mongoid/validatable/localizable.rb
mongoid-7.2.1 lib/mongoid/validatable/localizable.rb
mongoid-7.1.7 lib/mongoid/validatable/localizable.rb
mongoid-7.2.0 lib/mongoid/validatable/localizable.rb
mongoid-7.1.6 lib/mongoid/validatable/localizable.rb