123456789_123456789_123456789_123456789_123456789_

Exception: Mongoid::Errors::MongoidError

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, StandardError
Instance Chain:
self, StandardError
Inherits: StandardError
  • Object
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.

Constant Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#problem (readonly)

[ GitHub ]

  
# File 'lib/mongoid/errors/mongoid_error.rb', line 12

attr_reader :problem, :summary, :resolution

#resolution (readonly)

[ GitHub ]

  
# File 'lib/mongoid/errors/mongoid_error.rb', line 12

attr_reader :problem, :summary, :resolution

#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.

Examples:

Create the message

error.compose_message

Returns:

  • (String)

    The composed message.

[ GitHub ]

  
# File 'lib/mongoid/errors/mongoid_error.rb', line 22

def compose_message(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.

Examples:

Translate the message.

error.translate("errors", :key => value)

Parameters:

  • key (String)

    The key of the error in the locales.

  • options (Hash)

    The objects to pass to create the message.

Returns:

  • (String)

    A localized error message string.

[ GitHub ]

  
# File 'lib/mongoid/errors/mongoid_error.rb', line 48

def translate(key, options)
  ::I18n.translate("#{BASE_KEY}.#{key}", **options)
end

#translate_problem(key, attributes) ⇒ String (private)

Create the problem.

Examples:

Create the problem.

error.problem("error", {})

Parameters:

  • key (String | Symbol)

    The error key.

  • attributes (Hash)

    The attributes to interpolate.

Returns:

[ GitHub ]

  
# 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.

Examples:

Create the resolution.

error.resolution("error", {})

Parameters:

  • key (String | Symbol)

    The error key.

  • attributes (Hash)

    The attributes to interpolate.

Returns:

  • (String)

    The resolution.

[ GitHub ]

  
# 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.

Examples:

Create the summary.

error.summary("error", {})

Parameters:

  • key (String | Symbol)

    The error key.

  • attributes (Hash)

    The attributes to interpolate.

Returns:

[ GitHub ]

  
# File 'lib/mongoid/errors/mongoid_error.rb', line 74

def translate_summary(key, attributes)
  translate("#{key}.summary", attributes)
end