Class: SleepingKingStudios::Tools::Messages
- Defined in:
- lib/sleeping_king_studios/tools/messages.rb
Overview
Utility for generating configured, user-readable output strings.
Defined Under Namespace
Modules: Strategies Classes: Registry, Strategy
Instance Attribute Summary collapse
-
#registry ⇒ SleepingKingStudios::Tools::Messages::Registry
readonly
The strategies registry to use for the tool.
Instance Method Summary collapse
-
#initialize(registry:, toolbelt: nil) ⇒ Messages
constructor
A new instance of Messages.
-
#message(key, parameters: {}, scope: nil, **options) ⇒ Object
Generates a message from the given key, scope, and parameters.
Methods inherited from Base
Constructor Details
#initialize(registry:, toolbelt: nil) ⇒ Messages
Returns a new instance of Messages.
17 18 19 20 21 22 |
# File 'lib/sleeping_king_studios/tools/messages.rb', line 17 def initialize(registry:, toolbelt: nil) super(toolbelt:) @registry = registry || SleepingKingStudios::Tools::Messages::Registry.global end |
Instance Attribute Details
#registry ⇒ SleepingKingStudios::Tools::Messages::Registry (readonly)
Returns the strategies registry to use for the tool.
26 27 28 |
# File 'lib/sleeping_king_studios/tools/messages.rb', line 26 def registry @registry end |
Instance Method Details
#message(key, parameters: {}, scope: nil, **options) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/sleeping_king_studios/tools/messages.rb', line 42 def (key, parameters: {}, scope: nil, **) scoped_key = join_scope(key:, scope:) strategy = registry.get(scoped_key) return (scoped_key, **) unless strategy strategy.call(key, parameters:, scope:, **) end |