Class: Dry::Validation::Rust::Failures

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/validation/rust/failures.rb

Constant Summary collapse

IDENTIFIER_MESSAGES =
{
  acceptance: 'must be accepted',
  invalid: 'is invalid',
  taken: 'is already taken'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = []) ⇒ Failures

Returns a new instance of Failures.



15
16
17
18
# File 'lib/dry/validation/rust/failures.rb', line 15

def initialize(path = [])
  @path = Path.parse(path)
  @messages = []
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



13
14
15
# File 'lib/dry/validation/rust/failures.rb', line 13

def messages
  @messages
end

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/dry/validation/rust/failures.rb', line 13

def path
  @path
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/dry/validation/rust/failures.rb', line 26

def empty?
  messages.empty?
end

#failure(message, tokens = {}) ⇒ Object



20
21
22
23
24
# File 'lib/dry/validation/rust/failures.rb', line 20

def failure(message, tokens = {})
  text, code, meta = normalize(message, tokens)
  messages << Message.new(text: text, path: path, code: code, meta: meta, source: :rule)
  self
end