class Dry::Validation::Failures

Failure accumulator object

@api public

Attributes

opts[R]

Options for messages

These options are used by MessageResolver

@return [Hash]

@api private

path[R]

The path for messages accumulated by failures object

@return [Dry::Schema::Path]

@api private

Public Class Methods

new(path = ROOT_PATH) click to toggle source

@api private

# File lib/dry/validation/failures.rb, line 29
def initialize(path = ROOT_PATH)
  @path = Dry::Schema::Path[path]
  @opts = EMPTY_ARRAY.dup
end

Public Instance Methods

empty?() click to toggle source

@api private

# File lib/dry/validation/failures.rb, line 65
def empty?
  opts.empty?
end
failure(message, tokens = EMPTY_HASH) click to toggle source

Set failure

@overload failure(message)

Set message text explicitly
@param message [String] The message text
@example
  failure('this failed')

@overload failure(id)

Use message identifier (needs localized messages setup)
@param id [Symbol] The message id
@example
  failure(:taken)

@overload failure(meta_hash)

Use meta_hash[:text] as a message (either explicitely or as an identifier),
setting the rest of the hash as error meta attribute
@param meta [Hash] The hash containing the message as value for the :text key
@example
  failure({text: :invalid, key: value})

@see Evaluator#key @see Evaluator#base

@api public

# File lib/dry/validation/failures.rb, line 59
def failure(message, tokens = EMPTY_HASH)
  opts << {message: message, tokens: tokens, path: path}
  self
end