Exception: MongoModel::DocumentInvalid
- Inherits:
-
DocumentNotSaved
- Object
- StandardError
- DocumentNotSaved
- MongoModel::DocumentInvalid
- Defined in:
- lib/mongomodel/support/exceptions.rb
Overview
Raised by save!
and create!
when the document is invalid. Use the document
method to retrieve the document which did not validate.
begin
complex_operation_that_calls_save!_internally
rescue MongoModel::DocumentInvalid => invalid
puts invalid.document.errors
end
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
-
#initialize(document) ⇒ DocumentInvalid
constructor
A new instance of DocumentInvalid.
Constructor Details
#initialize(document) ⇒ DocumentInvalid
Returns a new instance of DocumentInvalid.
16 17 18 19 20 21 |
# File 'lib/mongomodel/support/exceptions.rb', line 16 def initialize(document) @document = document errors = @document.errors..join(I18n.t('support.array.words_connector', :default => ', ')) super(I18n.t('mongomodel.errors.messages.document_invalid', :errors => errors)) end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
14 15 16 |
# File 'lib/mongomodel/support/exceptions.rb', line 14 def document @document end |