Class: Dry::Validation::Rust::YamlBackend
- Inherits:
-
MessageBackend
- Object
- MessageBackend
- Dry::Validation::Rust::YamlBackend
- Defined in:
- lib/dry/validation/rust/message_backend.rb
Overview
Resolves messages from YAML translation files listed in MessageConfig#load_paths.
Instance Method Summary collapse
-
#initialize(config) ⇒ YamlBackend
constructor
A new instance of YamlBackend.
- #message(code:, predicate:, args:, type:, fallback:) ⇒ Object
Constructor Details
#initialize(config) ⇒ YamlBackend
Returns a new instance of YamlBackend.
48 49 50 51 52 53 |
# File 'lib/dry/validation/rust/message_backend.rb', line 48 def initialize(config) super @default_locale = config.default_locale.to_sym @top_namespace = config.top_namespace.to_s @translations = load_yaml(config.load_paths) end |
Instance Method Details
#message(code:, predicate:, args:, type:, fallback:) ⇒ Object
55 56 57 58 59 |
# File 'lib/dry/validation/rust/message_backend.rb', line 55 def (code:, predicate:, args:, type:, fallback:) key = predicate ? "#{predicate.to_s.delete_suffix('?')}?" : code.to_s template = @translations[[@default_locale, *@top_namespace.split('.'), 'errors', key].join('.')] template ? interpolate(template, tokens_for(args, type)) : fallback end |