Module: Mongoid::Validations
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Validations
- Included in:
- Components
- Defined in:
- lib/mongoid/validations.rb,
lib/mongoid/validations/format.rb,
lib/mongoid/validations/presence.rb,
lib/mongoid/validations/associated.rb,
lib/mongoid/validations/uniqueness.rb
Overview
:nodoc:
Defined Under Namespace
Modules: ClassMethods Classes: AssociatedValidator, FormatValidator, PresenceValidator, UniquenessValidator
Instance Method Summary collapse
-
#begin_validate ⇒ Object
Begin the associated validation.
-
#exit_validate ⇒ Object
Exit the associated validation.
-
#read_attribute_for_validation(attr) ⇒ Object
Overrides the default ActiveModel behaviour since we need to handle validations of relations slightly different than just calling the getter.
-
#valid?(context = nil) ⇒ true, false
Determine if the document is valid.
-
#validated? ⇒ true, false
Used to prevent infinite loops in associated validations.
Instance Method Details
#begin_validate ⇒ Object
Begin the associated validation.
21 22 23 |
# File 'lib/mongoid/validations.rb', line 21 def begin_validate Threaded.begin_validate(self) end |
#exit_validate ⇒ Object
Exit the associated validation.
31 32 33 |
# File 'lib/mongoid/validations.rb', line 31 def exit_validate Threaded.exit_validate(self) end |
#read_attribute_for_validation(attr) ⇒ Object
Overrides the default ActiveModel behaviour since we need to handle validations of relations slightly different than just calling the getter.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mongoid/validations.rb', line 47 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] && fields[attribute].localized? attributes[attribute] else send(attr) end end |
#valid?(context = nil) ⇒ true, false
Determine if the document is valid.
74 75 76 |
# File 'lib/mongoid/validations.rb', line 74 def valid?(context = nil) super context ? context : (new? ? :create : :update) end |
#validated? ⇒ true, false
Used to prevent infinite loops in associated validations.
86 87 88 |
# File 'lib/mongoid/validations.rb', line 86 def validated? Threaded.validated?(self) end |