Module: MongoModel::DocumentExtensions::Validations
- Extended by:
- ActiveSupport::Concern
- Included in:
- MongoModel::Document
- Defined in:
- lib/mongomodel/document/validations.rb,
lib/mongomodel/document/validations/uniqueness.rb
Defined Under Namespace
Modules: ClassMethods Classes: UniquenessValidator
Instance Method Summary collapse
-
#save(options = {}) ⇒ Object
The validation process on save can be skipped by passing
:validate => false
. -
#save!(options = {}) ⇒ Object
Attempts to save the document just like Document#save but will raise a DocumentInvalid exception instead of returning false if the document is not valid.
Instance Method Details
#save(options = {}) ⇒ Object
The validation process on save can be skipped by passing :validate => false
. The regular Document#save method is replaced with this when the validations module is mixed in, which it is by default.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mongomodel/document/validations.rb', line 30 def save(={}) if perform_validation() begin super rescue DocumentNotSaved valid? false end else false end end |
#save!(options = {}) ⇒ Object
Attempts to save the document just like Document#save but will raise a DocumentInvalid exception instead of returning false if the document is not valid.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mongomodel/document/validations.rb', line 45 def save!(={}) if perform_validation() begin super rescue DocumentNotSaved => e valid? ? raise : raise(DocumentInvalid.new(self)) end else raise DocumentInvalid.new(self) end end |