class Ruby::Enum::Errors::Base

Attributes

problem[R]

Problem occurred.

resolution[R]

Suggested problem resolution.

summary[R]

Summary of the problem.

Public Instance Methods

compose_message(key, attributes = {}) click to toggle source

Compose the message.

Parameters

key

Lookup key in the translation table.

attributes

The objects to pass to create the message.

# File lib/ruby-enum/errors/base.rb, line 20
def compose_message(key, attributes = {})
  @problem = create_problem(key, attributes)
  @summary = create_summary(key, attributes)
  @resolution = create_resolution(key, attributes)

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

Private Instance Methods

create_problem(key, attributes) click to toggle source

Create the problem.

Parameters

key

The error key.

attributes

The attributes to interpolate.

Returns the problem.

# File lib/ruby-enum/errors/base.rb, line 52
def create_problem(key, attributes)
  translate("#{key}.message", attributes)
end
create_resolution(key, attributes) click to toggle source

Create the resolution.

Parameters

key

The error key.

attributes

The attributes to interpolate.

Returns the resolution.

# File lib/ruby-enum/errors/base.rb, line 74
def create_resolution(key, attributes)
  translate("#{key}.resolution", attributes)
end
create_summary(key, attributes) click to toggle source

Create the summary.

Parameters

key

The error key.

attributes

The attributes to interpolate.

Returns the summary.

# File lib/ruby-enum/errors/base.rb, line 63
def create_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.

Parameters

key

The key of the error in the locales.

options

The objects to pass to create the message.

Returns a localized error message string.

# File lib/ruby-enum/errors/base.rb, line 41
def translate(key, options)
  ::I18n.translate("#{BASE_KEY}.#{key}", **{ locale: :en }.merge(options)).strip
end