Sha256: 38830eb672878af040974272115e319185264e4885e3c83909de8f92ab033c11

Contents?: true

Size: 824 Bytes

Versions: 15

Compression:

Stored size: 824 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

15 entries across 15 versions & 1 rubygems

Version Path
mongoid-8.1.7 lib/mongoid/validatable/localizable.rb
mongoid-8.1.6 lib/mongoid/validatable/localizable.rb
mongoid-8.0.8 lib/mongoid/validatable/localizable.rb
mongoid-8.1.5 lib/mongoid/validatable/localizable.rb
mongoid-8.1.4 lib/mongoid/validatable/localizable.rb
mongoid-8.0.7 lib/mongoid/validatable/localizable.rb
mongoid-8.1.3 lib/mongoid/validatable/localizable.rb
mongoid-8.1.2 lib/mongoid/validatable/localizable.rb
mongoid-8.0.6 lib/mongoid/validatable/localizable.rb
mongoid-8.1.1 lib/mongoid/validatable/localizable.rb
mongoid-8.0.5 lib/mongoid/validatable/localizable.rb
mongoid-8.1.0 lib/mongoid/validatable/localizable.rb
mongoid-8.0.4 lib/mongoid/validatable/localizable.rb
mongoid-8.0.3 lib/mongoid/validatable/localizable.rb
mongoid-8.0.2 lib/mongoid/validatable/localizable.rb