Class: Mongoid::Validations::FormatValidator

Inherits:
ActiveModel::Validations::FormatValidator
  • Object
show all
Defined in:
lib/mongoid/validations/format.rb

Overview

Validates that the specified attributes do or do not match a certain regular expression.

Examples:

Set up the format validator.


class Person
  include Mongoid::Document
  field :website

  validates_format_of :website, :with => URI.regexp
end

Instance Method Summary collapse

Instance Method Details

#validate_each(document, attribute, value) ⇒ Object

Validates each for format.

Examples:

Validate format.

validator.validate_each(model, :name, "value")

Parameters:

  • document (Document)

    The document.

  • attribute (Symbol, String)

    The attribute to validate.

  • value (Object)

    The attribute value.

Since:

  • 2.4.2



28
29
30
31
32
33
34
35
36
37
# File 'lib/mongoid/validations/format.rb', line 28

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