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/length.rb,
lib/mongoid/validations/macros.rb,
lib/mongoid/validations/presence.rb,
lib/mongoid/validations/queryable.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, Macros, Queryable Classes: AssociatedValidator, FormatValidator, LengthValidator, 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.
-
#validating_with_query? ⇒ true, false
Are we currently performing a validation that has a query?.
Instance Method Details
#begin_validate ⇒ Object
Begin the associated validation.
30 31 32 |
# File 'lib/mongoid/validations.rb', line 30 def begin_validate Threaded.begin_validate(self) end |
#exit_validate ⇒ Object
Exit the associated validation.
40 41 42 |
# File 'lib/mongoid/validations.rb', line 40 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.
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mongoid/validations.rb', line 56 def read_attribute_for_validation(attr) attribute = database_field_name(attr) if relations.has_key?(attribute) begin_validate relation = without_autobuild { send(attr) } exit_validate relation.do_or_do_not(:in_memory) || relation elsif fields[attribute].try(:localized?) attributes[attribute] else send(attr) end end |
#valid?(context = nil) ⇒ true, false
Determine if the document is valid.
83 84 85 |
# File 'lib/mongoid/validations.rb', line 83 def valid?(context = nil) super context ? context : (new_record? ? :create : :update) end |
#validated? ⇒ true, false
Used to prevent infinite loops in associated validations.
95 96 97 |
# File 'lib/mongoid/validations.rb', line 95 def validated? Threaded.validated?(self) end |
#validating_with_query? ⇒ true, false
Are we currently performing a validation that has a query?
107 108 109 |
# File 'lib/mongoid/validations.rb', line 107 def validating_with_query? self.class.validating_with_query? end |