Included Modules

Class/Module Index [+]

Quicksearch

Mongoid::Validations

This module provides additional validations that ActiveModel does not provide: validates_associated and validates_uniqueness_of.

Public Instance Methods

begin_validate() click to toggle source

Begin the associated validation.

@example Begin validation.

document.begin_validate

@since 2.1.9

# File lib/mongoid/validations.rb, line 18
def begin_validate
  Threaded.begin_validate(self)
end
exit_validate() click to toggle source

Exit the associated validation.

@example Exit validation.

document.exit_validate

@since 2.1.9

# File lib/mongoid/validations.rb, line 28
def exit_validate
  Threaded.exit_validate(self)
end
read_attribute_for_validation(attr) click to toggle source

Overrides the default ActiveModel behaviour since we need to handle validations of relations slightly different than just calling the getter.

@example Read the value.

person.read_attribute_for_validation(:addresses)

@param [ Symbol ] attr The name of the field or relation.

@return [ Object ] The value of the field or the relation.

@since 2.0.0.rc.1

# File lib/mongoid/validations.rb, line 44
def read_attribute_for_validation(attr)
  if relations[attr.to_s]
    begin_validate
    relation = send(attr)
    exit_validate
    relation.do_or_do_not(:in_memory) || relation
  else
    send(attr)
  end
end
valid?(context = nil) click to toggle source

Determine if the document is valid.

@example Is the document valid?

person.valid?

@example Is the document valid in a context?

person.valid?(:create)

@param [ Symbol ] context The optional validation context.

@return [ true, false ] True if valid, false if not.

@since 2.0.0.rc.6

# File lib/mongoid/validations.rb, line 68
def valid?(context = nil)
  super context ? context : (new? ? :create : :update)
end
validated?() click to toggle source

Used to prevent infinite loops in associated validations.

@example Is the document validated?

document.validated?

@return [ true, false ] Has the document already been validated?

@since 2.0.0.rc.2

# File lib/mongoid/validations.rb, line 80
def validated?
  Threaded.validated?(self)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.