Exception: Mongoid::Errors::MongoidError
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.
Constant Summary
-
BASE_KEY =
# File 'lib/mongoid/errors/mongoid_error.rb', line 14"mongoid.errors.messages"
Instance Attribute Summary
- #problem readonly
- #resolution readonly
- #summary readonly
Instance Method Summary
-
#compose_message(key, attributes = {}) ⇒ String
Compose the message.
-
#translate(key, options) ⇒ String
private
Given the key of the specific error and the options hash, translate the message.
-
#translate_problem(key, attributes) ⇒ String
private
Create the problem.
-
#translate_resolution(key, attributes) ⇒ String
private
Create the resolution.
-
#translate_summary(key, attributes) ⇒ String
private
Create the summary.
Instance Attribute Details
#problem (readonly)
[ GitHub ]# File 'lib/mongoid/errors/mongoid_error.rb', line 12
attr_reader :problem, :summary, :resolution
#resolution (readonly)
[ GitHub ]#summary (readonly)
[ GitHub ]# File 'lib/mongoid/errors/mongoid_error.rb', line 12
attr_reader :problem, :summary, :resolution
Instance Method Details
#compose_message(key, attributes = {}) ⇒ String
Compose the message.
# File 'lib/mongoid/errors/mongoid_error.rb', line 22
def (key, attributes = {}) @problem = translate_problem(key, attributes) @summary = translate_summary(key, attributes) @resolution = translate_resolution(key, attributes) @problem_title = translate("message_title", {}) @summary_title = translate("summary_title", {}) @resolution_title = translate("resolution_title", {}) "\n#{@problem_title}:\n #{@problem&.strip}"+ "\n#{@summary_title}:\n #{@summary&.strip}"+ "\n#{@resolution_title}:\n #{@resolution&.strip}" end
#translate(key, options) ⇒ String (private)
Given the key of the specific error and the options hash, translate the message.
# File 'lib/mongoid/errors/mongoid_error.rb', line 48
def translate(key, ) ::I18n.translate("#{BASE_KEY}.#{key}", ** ) end
#translate_problem(key, attributes) ⇒ String (private)
Create the problem.
# File 'lib/mongoid/errors/mongoid_error.rb', line 61
def translate_problem(key, attributes) translate("#{key}.message", attributes) end
#translate_resolution(key, attributes) ⇒ String (private)
Create the resolution.
# File 'lib/mongoid/errors/mongoid_error.rb', line 87
def translate_resolution(key, attributes) translate("#{key}.resolution", attributes) end
#translate_summary(key, attributes) ⇒ String (private)
Create the summary.
# File 'lib/mongoid/errors/mongoid_error.rb', line 74
def translate_summary(key, attributes) translate("#{key}.summary", attributes) end