Class: Dry::Schema::Messages::Namespaced

Inherits:
Abstract
  • Object
show all
Defined in:
lib/dry/schema/messages/namespaced.rb

Overview

Namespaced messages backend

Instance Attribute Summary collapse

Instance Method Summary collapse

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, messages)
  super()
  @config = messages.config
  @namespace = namespace
  @messages = messages
  @call_opts = {namespace: namespace}.freeze
end

Instance Attribute Details

#call_optsObject (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

#configObject (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

#messagesObject (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
  @messages
end

#namespaceObject (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, options)
  messages.cache_key(predicate, options)
end

#call(key, options = {}) ⇒ Object Also known as: []



44
45
46
# File 'lib/dry/schema/messages/namespaced.rb', line 44

def call(key, options = {})
  super(key, options.empty? ? call_opts : options.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

Parameters:

  • key (Symbol)
  • options (Hash) (defaults to: {})

Returns:

  • (String)


39
40
41
# File 'lib/dry/schema/messages/namespaced.rb', line 39

def get(key, options = {})
  messages.get(key, options)
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, options, **data)
  messages.interpolatable_data(key, options, **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, options, **data)
  messages.interpolate(key, options, **data)
end

#key?(key, *args) ⇒ Boolean

Check if given key is defined

Returns:

  • (Boolean)


54
55
56
# File 'lib/dry/schema/messages/namespaced.rb', line 54

def key?(key, *args)
  messages.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 = messages.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)
  messages.translate(key, **args)
end