Class: Dry::Validation::Messages::Namespaced

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

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, #hash, #lookup, #namespaced, #rule

Constructor Details

#initialize(namespace, messages) ⇒ Namespaced

Returns a new instance of Namespaced.



7
8
9
10
11
12
# File 'lib/dry/validation/messages/namespaced.rb', line 7

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

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



5
6
7
# File 'lib/dry/validation/messages/namespaced.rb', line 5

def messages
  @messages
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



5
6
7
# File 'lib/dry/validation/messages/namespaced.rb', line 5

def namespace
  @namespace
end

#rootObject (readonly)

Returns the value of attribute root.



5
6
7
# File 'lib/dry/validation/messages/namespaced.rb', line 5

def root
  @root
end

Instance Method Details

#default_localeObject



26
27
28
# File 'lib/dry/validation/messages/namespaced.rb', line 26

def default_locale
  messages.default_locale
end

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



18
19
20
# File 'lib/dry/validation/messages/namespaced.rb', line 18

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

#key?(key, *args) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/dry/validation/messages/namespaced.rb', line 14

def key?(key, *args)
  messages.key?(key, *args)
end

#lookup_paths(tokens) ⇒ Object



22
23
24
# File 'lib/dry/validation/messages/namespaced.rb', line 22

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