Class: Servus::Support::MessageResolver
- Inherits:
-
Object
- Object
- Servus::Support::MessageResolver
- Defined in:
- lib/servus/support/message_resolver.rb
Overview
Resolves message templates with interpolation support.
Handles multiple template formats:
- String: Static or with %key / %
s interpolation - Symbol: I18n key lookup with fallback
- Hash: Inline translations keyed by locale
- Proc: Dynamic template evaluated at runtime
Instance Attribute Summary collapse
-
#data ⇒ Hash, ...
readonly
The interpolation data or data-providing block.
-
#i18n_scope ⇒ String?
readonly
The I18n scope prefix for symbol templates.
-
#template ⇒ String, ...
readonly
The message template.
Instance Method Summary collapse
-
#initialize(template:, data: nil, i18n_scope: nil) ⇒ MessageResolver
constructor
Creates a new message resolver.
-
#resolve(context: nil) ⇒ String
Resolves the template to a final string.
Constructor Details
#initialize(template:, data: nil, i18n_scope: nil) ⇒ MessageResolver
Creates a new message resolver.
51 52 53 54 55 |
# File 'lib/servus/support/message_resolver.rb', line 51 def initialize(template:, data: nil, i18n_scope: nil) @template = template @data = data @i18n_scope = i18n_scope end |
Instance Attribute Details
#data ⇒ Hash, ... (readonly)
Returns the interpolation data or data-providing block.
41 42 43 |
# File 'lib/servus/support/message_resolver.rb', line 41 def data @data end |
#i18n_scope ⇒ String? (readonly)
Returns the I18n scope prefix for symbol templates.
44 45 46 |
# File 'lib/servus/support/message_resolver.rb', line 44 def i18n_scope @i18n_scope end |
#template ⇒ String, ... (readonly)
Returns the message template.
38 39 40 |
# File 'lib/servus/support/message_resolver.rb', line 38 def template @template end |
Instance Method Details
#resolve(context: nil) ⇒ String
Resolves the template to a final string.
61 62 63 64 65 66 |
# File 'lib/servus/support/message_resolver.rb', line 61 def resolve(context: nil) resolved_template = resolve_template(context) resolved_data = resolve_data(context) interpolate(resolved_template, resolved_data) end |