Sha256: 2ea9e98a6f5882d0fd52f5f8a0b06550859bd5fcc0ddb6277d119ff3fc6598d7

Contents?: true

Size: 1.11 KB

Versions: 58

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Validations #:nodoc:

    # Validates that the specified attributes do or do not match a certain 
    # regular expression.
    #
    # @example Set up the format validator.
    #
    #   class Person
    #     include Mongoid::Document
    #     field :website
    #
    #     validates_format_of :website, :with => URI.regexp
    #   end
    class FormatValidator < ActiveModel::Validations::FormatValidator

      # Validates each for format.
      #
      # @example Validate format.
      #   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[attribute.to_s]
        if field && field.localized? && !value.blank?
          value.each_pair do |_locale, _value|
            super(document, attribute, _value)
          end
        else
          super
        end
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 3 rubygems

Version Path
classiccms-0.5.13 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.5.12 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.5.11 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.5.10 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.5.9 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.5.8 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.5.7 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.5.6 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.5.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.5.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.5.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.5.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.4.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.4.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.4.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.3.9 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.3.8 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.3.7 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.3.6 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb
classiccms-0.3.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/validations/format.rb