Module: Mongoid::Validatable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Composable
- Defined in:
- build/mongoid-8.1/lib/mongoid/validatable.rb,
build/mongoid-8.1/lib/mongoid/validatable/format.rb,
build/mongoid-8.1/lib/mongoid/validatable/length.rb,
build/mongoid-8.1/lib/mongoid/validatable/macros.rb,
build/mongoid-8.1/lib/mongoid/validatable/presence.rb,
build/mongoid-8.1/lib/mongoid/validatable/queryable.rb,
build/mongoid-8.1/lib/mongoid/validatable/associated.rb,
build/mongoid-8.1/lib/mongoid/validatable/uniqueness.rb,
build/mongoid-8.1/lib/mongoid/validatable/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.
-
#performing_validations?(options = {}) ⇒ true | false
Given the provided options, are we performing validations?.
-
#read_attribute_for_validation(attr) ⇒ Object
Overrides the default ActiveModel behavior since we need to handle validations of associations 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.
28 29 30 |
# File 'build/mongoid-8.1/lib/mongoid/validatable.rb', line 28 def begin_validate Threaded.begin_validate(self) end |
#exit_validate ⇒ Object
Exit the associated validation.
36 37 38 |
# File 'build/mongoid-8.1/lib/mongoid/validatable.rb', line 36 def exit_validate Threaded.exit_validate(self) end |
#performing_validations?(options = {}) ⇒ true | false
Given the provided options, are we performing validations?
50 51 52 |
# File 'build/mongoid-8.1/lib/mongoid/validatable.rb', line 50 def performing_validations?( = {}) [:validate].nil? ? true : [:validate] end |
#read_attribute_for_validation(attr) ⇒ Object
Overrides the default ActiveModel behavior since we need to handle validations of associations slightly different than just calling the getter.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'build/mongoid-8.1/lib/mongoid/validatable.rb', line 64 def read_attribute_for_validation(attr) attribute = database_field_name(attr) if relations.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.
89 90 91 |
# File 'build/mongoid-8.1/lib/mongoid/validatable.rb', line 89 def valid?(context = nil) super context ? context : (new_record? ? :create : :update) end |
#validated? ⇒ true | false
Used to prevent infinite loops in associated validations.
99 100 101 |
# File 'build/mongoid-8.1/lib/mongoid/validatable.rb', line 99 def validated? Threaded.validated?(self) end |
#validating_with_query? ⇒ true | false
Are we currently performing a validation that has a query?
109 110 111 |
# File 'build/mongoid-8.1/lib/mongoid/validatable.rb', line 109 def validating_with_query? self.class.validating_with_query? end |