Exception: Mongoid::Errors::Validations

Inherits:
MongoidError
  • Object
show all
Defined in:
build/mongoid-8.1/lib/mongoid/errors/validations.rb

Overview

Raised when a persistence method ending in ! fails validation. The message will contain the full error messages from the Document in question.

Examples:

Create the error.

Validations.new(person.errors)

Constant Summary

Constants inherited from MongoidError

MongoidError::BASE_KEY

Instance Attribute Summary collapse

Attributes inherited from MongoidError

#problem, #resolution, #summary

Instance Method Summary collapse

Methods inherited from MongoidError

#compose_message

Constructor Details

#initialize(document) ⇒ Validations

Returns a new instance of Validations.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'build/mongoid-8.1/lib/mongoid/errors/validations.rb', line 15

def initialize(document)
  @document = document

  super(
    compose_message(
      "validations",
      {
        document: document.class,
        errors: document.errors.full_messages.join(", ")
      }
    )
  )
end

Instance Attribute Details

#documentObject (readonly) Also known as: record

Returns the value of attribute document.



12
13
14
# File 'build/mongoid-8.1/lib/mongoid/errors/validations.rb', line 12

def document
  @document
end