Exception: LcpRuby::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/lcp_ruby.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_or_key = nil, **interpolations) ⇒ Error

Returns a new instance of Error.



317
318
319
320
321
322
323
324
325
326
327
# File 'lib/lcp_ruby.rb', line 317

def initialize(message_or_key = nil, **interpolations)
  if message_or_key.is_a?(Symbol) || (message_or_key.is_a?(String) && message_or_key.start_with?("lcp_ruby."))
    @i18n_key = message_or_key.to_s
    @i18n_interpolations = interpolations
    # Backend bypasses enforce_available_locales; I18n.t(locale: :en)
    # would raise InvalidLocale when :en isn't in available_locales.
    super(I18n.backend.translate(:en, @i18n_key, default: @i18n_key, **interpolations))
  else
    super(message_or_key)
  end
end

Instance Attribute Details

#i18n_interpolationsObject (readonly)

Returns the value of attribute i18n_interpolations.



315
316
317
# File 'lib/lcp_ruby.rb', line 315

def i18n_interpolations
  @i18n_interpolations
end

#i18n_keyObject (readonly)

Returns the value of attribute i18n_key.



315
316
317
# File 'lib/lcp_ruby.rb', line 315

def i18n_key
  @i18n_key
end

Instance Method Details

#localized_messageObject



329
330
331
332
# File 'lib/lcp_ruby.rb', line 329

def localized_message
  return message unless @i18n_key
  I18n.t(@i18n_key, **(@i18n_interpolations || {}), default: message)
end