Class: Yes::Core::ErrorMessages

Inherits:
Object
  • Object
show all
Defined in:
lib/yes/core/error_messages.rb

Overview

Helper class for looking up error messages from I18n

Class Method Summary collapse

Class Method Details

.guard_error(context_name, aggregate_name, command_name, guard_name) ⇒ String

Looks up the error message for a guard from I18n translations

Parameters:

  • context_name (String)

    The context name

  • aggregate_name (String)

    The aggregate name

  • command_name (String)

    The command name

  • guard_name (Symbol)

    The name of the guard

Returns:

  • (String)

    The error message



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/yes/core/error_messages.rb', line 15

def guard_error(context_name, aggregate_name, command_name, guard_name)
  context_key, aggregate_key, command_key, guard_key = normalize_keys(
    context_name, aggregate_name, command_name, guard_name
  )

  # Try to find the error message in the following order:
  # 1. Specific translation for this aggregate attribute guard
  # 2. Default fallback message
  I18n.t(
    "aggregates.#{context_key}.#{aggregate_key}.commands.#{command_key}.guards.#{guard_key}.error",
    default: "Guard '#{guard_key}' failed"
  )
end