Module: Mongoid::Validations
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Validations
- Included in:
- Components
- Defined in:
- lib/mongoid/validations.rb,
lib/mongoid/validations/length.rb,
lib/mongoid/validations/format.rb,
lib/mongoid/validations/presence.rb,
lib/mongoid/validations/associated.rb,
lib/mongoid/validations/uniqueness.rb,
lib/mongoid/validations/localizable.rb
Overview
This module provides additional validations that ActiveModel does not provide: validates_associated and validates_uniqueness_of.
Defined Under Namespace
Modules: ClassMethods, Localizable Classes: AssociatedValidator, FormatValidator, LengthValidator, PresenceValidator, UniquenessValidator
Instance Method Summary (collapse)
-
- (Object) begin_validate
Begin the associated validation.
-
- (Object) exit_validate
Exit the associated validation.
-
- (Object) read_attribute_for_validation(attr)
Overrides the default ActiveModel behaviour since we need to handle validations of relations slightly different than just calling the getter.
-
- (true, false) valid?(context = nil)
Determine if the document is valid.
-
- (true, false) validated?
Used to prevent infinite loops in associated validations.
Instance Method Details
- (Object) begin_validate
Begin the associated validation.
23 24 25 |
# File 'lib/mongoid/validations.rb', line 23 def begin_validate Threaded.begin_validate(self) end |
- (Object) exit_validate
Exit the associated validation.
33 34 35 |
# File 'lib/mongoid/validations.rb', line 33 def exit_validate Threaded.exit_validate(self) end |
- (Object) read_attribute_for_validation(attr)
Overrides the default ActiveModel behaviour since we need to handle validations of relations slightly different than just calling the getter.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mongoid/validations.rb', line 49 def read_attribute_for_validation(attr) attribute = attr.to_s if relations[attribute] begin_validate relation = send(attr) exit_validate relation.do_or_do_not(:in_memory) || relation elsif fields[attribute].try(:localized?) attributes[attribute] else send(attr) end end |
- (true, false) valid?(context = nil)
Determine if the document is valid.
76 77 78 |
# File 'lib/mongoid/validations.rb', line 76 def valid?(context = nil) super context ? context : (new_record? ? :create : :update) end |
- (true, false) validated?
Used to prevent infinite loops in associated validations.
88 89 90 |
# File 'lib/mongoid/validations.rb', line 88 def validated? Threaded.validated?(self) end |