Class: Dry::Schema::Messages::Namespaced
- Defined in:
- lib/dry/schema/messages/namespaced.rb
Overview
Namespaced messages backend
Instance Attribute Summary collapse
- #call_opts ⇒ Object readonly private
- #config ⇒ Object readonly private
- #messages ⇒ Object readonly private
- #namespace ⇒ Object readonly private
Instance Method Summary collapse
- #cache_key(predicate, options) ⇒ Object private
- #call(key, options = {}) ⇒ Object (also: #[])
- #filled_lookup_paths(tokens) ⇒ Object private
-
#get(key, options = {}) ⇒ String
Get a message for the given key and its options.
-
#initialize(namespace, messages) ⇒ Namespaced
constructor
private
A new instance of Namespaced.
- #interpolatable_data(key, options, **data) ⇒ Object private
- #interpolate(key, options, **data) ⇒ Object private
-
#key?(key, *args) ⇒ Boolean
Check if given key is defined.
- #rule_lookup_paths(tokens) ⇒ Object private
- #translate(key, **args) ⇒ Object private
Methods inherited from Abstract
build, #default_locale, #looked_up_paths, #lookup_paths, #namespaced, #root, #rule, setting_names
Constructor Details
#initialize(namespace, messages) ⇒ Namespaced
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Namespaced.
23 24 25 26 27 28 29 |
# File 'lib/dry/schema/messages/namespaced.rb', line 23 def initialize(namespace, ) super() @config = .config @namespace = namespace @messages = @call_opts = {namespace: namespace}.freeze end |
Instance Attribute Details
#call_opts ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/dry/schema/messages/namespaced.rb', line 20 def call_opts @call_opts end |
#config ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 |
# File 'lib/dry/schema/messages/namespaced.rb', line 17 def config @config end |
#messages ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/dry/schema/messages/namespaced.rb', line 14 def @messages end |
#namespace ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
11 12 13 |
# File 'lib/dry/schema/messages/namespaced.rb', line 11 def namespace @namespace end |
Instance Method Details
#cache_key(predicate, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 |
# File 'lib/dry/schema/messages/namespaced.rb', line 72 def cache_key(predicate, ) .cache_key(predicate, ) end |
#call(key, options = {}) ⇒ Object Also known as: []
44 45 46 |
# File 'lib/dry/schema/messages/namespaced.rb', line 44 def call(key, = {}) super(key, .empty? ? call_opts : .merge(call_opts)) end |
#filled_lookup_paths(tokens) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 |
# File 'lib/dry/schema/messages/namespaced.rb', line 59 def filled_lookup_paths(tokens) super(tokens.merge(root: "#{tokens[:root]}.#{namespace}")) + super end |
#get(key, options = {}) ⇒ String
Get a message for the given key and its options
39 40 41 |
# File 'lib/dry/schema/messages/namespaced.rb', line 39 def get(key, = {}) .get(key, ) end |
#interpolatable_data(key, options, **data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
77 78 79 |
# File 'lib/dry/schema/messages/namespaced.rb', line 77 def interpolatable_data(key, , **data) .interpolatable_data(key, , **data) end |
#interpolate(key, options, **data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 |
# File 'lib/dry/schema/messages/namespaced.rb', line 82 def interpolate(key, , **data) .interpolate(key, , **data) end |
#key?(key, *args) ⇒ Boolean
Check if given key is defined
54 55 56 |
# File 'lib/dry/schema/messages/namespaced.rb', line 54 def key?(key, *args) .key?(key, *args) end |
#rule_lookup_paths(tokens) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
64 65 66 67 68 69 |
# File 'lib/dry/schema/messages/namespaced.rb', line 64 def rule_lookup_paths(tokens) base_paths = .rule_lookup_paths(tokens) base_paths.map { |key| key.sub(config.top_namespace, "#{config.top_namespace}.#{namespace}") } + base_paths end |
#translate(key, **args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
87 88 89 |
# File 'lib/dry/schema/messages/namespaced.rb', line 87 def translate(key, **args) .translate(key, **args) end |