Module: MongoODM::Document::Validations::InstanceMethods
- Defined in:
- lib/mongo_odm/document/validations.rb
Instance Method Summary collapse
-
#save_with_validation(options = nil) ⇒ Object
The validation process on save can be skipped by passing false.
-
#valid? ⇒ Boolean
Runs all the specified validations and returns true if no errors were added otherwise false.
Instance Method Details
#save_with_validation(options = nil) ⇒ Object
The validation process on save can be skipped by passing false. The regular Base#save method is replaced with this when the validations module is mixed in, which it is by default.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mongo_odm/document/validations.rb', line 22 def save_with_validation(=nil) perform_validation = case when NilClass true when Hash [:validate] != false end if perform_validation && valid? || !perform_validation save_without_validation else false end end |
#valid? ⇒ Boolean
Runs all the specified validations and returns true if no errors were added otherwise false.
38 39 40 41 42 |
# File 'lib/mongo_odm/document/validations.rb', line 38 def valid? errors.clear run_callbacks(:validate) errors.empty? end |