class TinyDyno::Errors::TinyDynoError

Constants

BASE_KEY

Public Instance Methods

compose_message(key, attributes) click to toggle source

Compose the message.

@example Create the message

error.compose_message

@return [ String ] The composed message.

# File lib/tiny_dyno/errors/tiny_dyno_error.rb, line 13
def compose_message(key, attributes)
  @problem = problem(key, attributes)
  @summary = summary(key, attributes)
  @resolution = resolution(key, attributes)

  "\nProblem:\n  #{@problem}"+
      "\nSummary:\n  #{@summary}"+
      "\nResolution:\n  #{@resolution}"
end

Private Instance Methods

problem(key, attributes) click to toggle source

Create the problem.

@example Create the problem.

error.problem("error", {})

@param [ String, Symbol ] key The error key. @param [ Hash ] attributes The attributes to interpolate.

@return [ String ] The problem.

@since 3.0.0

# File lib/tiny_dyno/errors/tiny_dyno_error.rb, line 50
def problem(key, attributes)
  translate("#{key}.message", attributes)
end
resolution(key, attributes) click to toggle source

Create the resolution.

@example Create the resolution.

error.resolution("error", {})

@param [ String, Symbol ] key The error key. @param [ Hash ] attributes The attributes to interpolate.

@return [ String ] The resolution.

@since 3.0.0

# File lib/tiny_dyno/errors/tiny_dyno_error.rb, line 80
def resolution(key, attributes)
  translate("#{key}.resolution", attributes)
end
summary(key, attributes) click to toggle source

Create the summary.

@example Create the summary.

error.summary("error", {})

@param [ String, Symbol ] key The error key. @param [ Hash ] attributes The attributes to interpolate.

@return [ String ] The summary.

@since 3.0.0

# File lib/tiny_dyno/errors/tiny_dyno_error.rb, line 65
def summary(key, attributes)
  translate("#{key}.summary", attributes)
end
translate(key, options) click to toggle source

Given the key of the specific error and the options hash, translate the message.

@example Translate the message.

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

@param [ String ] key The key of the error in the locales. @param [ Hash ] options The objects to pass to create the message.

@return [ String ] A localized error message string.

# File lib/tiny_dyno/errors/tiny_dyno_error.rb, line 35
def translate(key, options)
  ::I18n.translate("#{BASE_KEY}.#{key}", options)
end