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

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

Overview

Namespaced messages backend

Constant Summary

Constants inherited from Abstract

Abstract::DEFAULT_PATH

Instance Attribute Summary collapse

Attributes inherited from Abstract

#config

Instance Method Summary collapse

Methods inherited from Abstract

cache, #cache, #call, #default_locale, #hash, #lookup, #namespaced, #rule

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.



18
19
20
21
22
23
# File 'lib/dry/schema/messages/namespaced.rb', line 18

def initialize(namespace, messages)
  super()
  @namespace = namespace
  @messages = messages
  @root = messages.root
end

Instance Attribute Details

#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.



12
13
14
# File 'lib/dry/schema/messages/namespaced.rb', line 12

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.



9
10
11
# File 'lib/dry/schema/messages/namespaced.rb', line 9

def namespace
  @namespace
end

#rootObject (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.



15
16
17
# File 'lib/dry/schema/messages/namespaced.rb', line 15

def root
  @root
end

Instance Method Details

#get(key, options = {}) ⇒ String

Get a message for the given key and its options

Parameters:

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

Returns:

  • (String)


33
34
35
# File 'lib/dry/schema/messages/namespaced.rb', line 33

def get(key, options = {})
  messages.get(key, options)
end

#key?(key, *args) ⇒ Boolean

Check if given key is defined

Returns:

  • (Boolean)


42
43
44
# File 'lib/dry/schema/messages/namespaced.rb', line 42

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



47
48
49
# File 'lib/dry/schema/messages/namespaced.rb', line 47

def lookup_paths(tokens)
  super(tokens.merge(root: "#{root}.rules.#{namespace}")) + super
end