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::CACHE_KEYS, Abstract::DEFAULT_PATH

Instance Attribute Summary collapse

Attributes inherited from Abstract

#config

Instance Method Summary collapse

Methods inherited from Abstract

cache, #cache, #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

#call(predicate, options = EMPTY_HASH) ⇒ Object Also known as: []



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

def call(predicate, options = EMPTY_HASH)
  super do |path, opts|
    messages.get(path, opts)
  end
end

#default_localeObject



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

def default_locale
  messages.default_locale
end

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



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

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

#key?(key, *args) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#lookup_paths(tokens) ⇒ Object



29
30
31
# File 'lib/dry/validation/messages/namespaced.rb', line 29

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