Class: SleepingKingStudios::Tools::Messages::Strategy

Inherits:
Object
  • Object
show all
Defined in:
lib/sleeping_king_studios/tools/messages/strategy.rb

Overview

Abstract class for converting parameterized keys to user-readable messages.

Instance Method Summary collapse

Instance Method Details

#call(key, parameters: {}, scope: nil, **options) ⇒ String

Generates a formatted string for the given key, parameters, and options.

Parameters:

  • key (String, Symbol)

    the key used to resolve the message.

  • parameters (Hash) (defaults to: {})

    the parameters used to generate the message, such as values for a template string.

  • scope (String) (defaults to: nil)

    the namespace for the key. Combined with the given key to generate the scoped key value.

  • options (Hash)

    additional options for resolving or generating the message.

Returns:

  • (String)

    the generated template string, or a generic error string if a message is not defined for the given key and parameters.



21
22
23
24
25
26
27
28
# File 'lib/sleeping_king_studios/tools/messages/strategy.rb', line 21

def call(key, parameters: {}, scope: nil, **)
  scoped_key = join_scope(key:, scope:)
  template   = template_for(scoped_key, **)

  return missing_message(scoped_key, **) unless template

  generate(template, parameters:, scoped_key:, **)
end