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

Instance Method Summary collapse

Methods inherited from Abstract

#cache, #call, #config, #lookup, #namespaced

Constructor Details

#initialize(namespace, messages) ⇒ Namespaced

Returns a new instance of Namespaced.



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

def initialize(namespace, messages)
  @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

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



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

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

#key?(key, *args) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#lookup_paths(tokens) ⇒ Object



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

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