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
- #call(key, options = {}) ⇒ Object (also: #[])
-
#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.
-
#key?(key, *args) ⇒ Boolean
Check if given key is defined.
- #lookup_paths(tokens) ⇒ Object private
- #rule_lookup_paths(tokens) ⇒ Object private
Methods inherited from Abstract
build, cache, #cache, #default_locale, #lookup, #namespaced, #root, #rule, #translate
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 |
# File 'lib/dry/schema/messages/namespaced.rb', line 23 def initialize(namespace, ) @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
#call(key, options = {}) ⇒ Object Also known as: []
43 44 45 |
# File 'lib/dry/schema/messages/namespaced.rb', line 43 def call(key, = {}) super(key, .empty? ? call_opts : .merge(call_opts)) end |
#get(key, options = {}) ⇒ String
Get a message for the given key and its options
38 39 40 |
# File 'lib/dry/schema/messages/namespaced.rb', line 38 def get(key, = {}) .get(key, ) end |
#key?(key, *args) ⇒ Boolean
Check if given key is defined
53 54 55 |
# File 'lib/dry/schema/messages/namespaced.rb', line 53 def key?(key, *args) .key?(key, *args) end |
#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.
58 59 60 |
# File 'lib/dry/schema/messages/namespaced.rb', line 58 def lookup_paths(tokens) super(tokens.merge(root: "#{tokens[:root]}.#{namespace}")) + super 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.
63 64 65 66 |
# File 'lib/dry/schema/messages/namespaced.rb', line 63 def rule_lookup_paths(tokens) base_paths = .rule_lookup_paths(tokens) base_paths.map { |key| key.gsub('dry_schema', "dry_schema.#{namespace}") } + base_paths end |