Exception: Mongoid::Errors::MongoidError
- Inherits:
-
StandardError
- Object
- StandardError
- Mongoid::Errors::MongoidError
- Defined in:
- lib/mongoid/errors/mongoid_error.rb
Overview
Default parent Mongoid error for all custom errors. This handles the base key for the translations and provides the convenience method for translating the messages.
Direct Known Subclasses
AmbiguousRelationship, Callback, DeleteRestriction, DocumentNotFound, EagerLoad, InvalidCollection, InvalidConfigOption, InvalidDatabase, InvalidField, InvalidFieldOption, InvalidFind, InvalidIndex, InvalidOptions, InvalidScope, InvalidSetPolymorphicRelation, InvalidStorageOptions, InvalidTime, InverseNotFound, MixedRelations, MixedSessionConfiguration, NestedAttributesMetadataNotFound, NoDefaultSession, NoEnvironment, NoMapReduceOutput, NoMetadata, NoParent, NoSessionConfig, NoSessionDatabase, NoSessionHosts, NoSessionsConfig, ReadonlyAttribute, ScopeOverwrite, TooManyNestedAttributeRecords, UnknownAttribute, UnsavedDocument, UnsupportedJavascript, UnsupportedVersion, Validations, VersioningNotOnRoot, MultiParameterAttributes::Errors::AttributeAssignmentError, MultiParameterAttributes::Errors::MultiparameterAssignmentErrors
Constant Summary collapse
- BASE_KEY =
"mongoid.errors.messages"
Instance Method Summary collapse
-
#compose_message(key, attributes) ⇒ String
Compose the message.
-
#problem(key, attributes) ⇒ String
Create the problem.
-
#resolution(key, attributes) ⇒ String
Create the resolution.
-
#summary(key, attributes) ⇒ String
Create the summary.
-
#translate(key, options) ⇒ String
Given the key of the specific error and the options hash, translate the message.
Instance Method Details
#compose_message(key, attributes) ⇒ String
Compose the message.
20 21 22 23 24 |
# File 'lib/mongoid/errors/mongoid_error.rb', line 20 def (key, attributes) "\nProblem:\n #{problem(key, attributes)}"+ "\nSummary:\n #{summary(key, attributes)}"+ "\nResolution:\n #{resolution(key, attributes)}" end |
#problem(key, attributes) ⇒ String
Create the problem.
48 49 50 |
# File 'lib/mongoid/errors/mongoid_error.rb', line 48 def problem(key, attributes) translate("#{key}.message", attributes) end |
#resolution(key, attributes) ⇒ String
Create the resolution.
72 73 74 |
# File 'lib/mongoid/errors/mongoid_error.rb', line 72 def resolution(key, attributes) translate("#{key}.resolution", attributes) end |
#summary(key, attributes) ⇒ String
Create the summary.
60 61 62 |
# File 'lib/mongoid/errors/mongoid_error.rb', line 60 def summary(key, attributes) translate("#{key}.summary", attributes) end |
#translate(key, options) ⇒ String
Given the key of the specific error and the options hash, translate the message.
36 37 38 |
# File 'lib/mongoid/errors/mongoid_error.rb', line 36 def translate(key, ) ::I18n.translate("#{BASE_KEY}.#{key}", { locale: :en }.merge()) end |