Class: Dry::Validation::Message

Inherits:
Schema::Message
  • Object
show all
Defined in:
lib/dry/validation/message.rb

Overview

Message message

Direct Known Subclasses

Localized

Defined Under Namespace

Classes: Localized

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, path:, meta: EMPTY_HASH) ⇒ Message

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new error object



73
74
75
76
77
# File 'lib/dry/validation/message.rb', line 73

def initialize(text, path:, meta: EMPTY_HASH)
  @text = text
  @path = Array(path)
  @meta = meta
end

Instance Attribute Details

#metaHash (readonly)

Optional hash with meta-data

Returns:

  • (Hash)


35
36
37
# File 'lib/dry/validation/message.rb', line 35

def meta
  @meta
end

#pathArray<Symbol, Integer> (readonly)

The path to the value with the error

Returns:

  • (Array<Symbol, Integer>)


28
29
30
# File 'lib/dry/validation/message.rb', line 28

def path
  @path
end

#textString (readonly)

The error message text

Returns:

  • (String)

    text



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

def text
  @text
end

Class Method Details

.[](text, path, meta) ⇒ Message, Message::Localized

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build an error



65
66
67
68
# File 'lib/dry/validation/message.rb', line 65

def self.[](text, path, meta)
  klass = text.respond_to?(:call) ? Localized : Message
  klass.new(text, path: path, meta: meta)
end

Instance Method Details

#base?Boolean

Check if this is a base error not associated with any key

Returns:

  • (Boolean)


84
85
86
# File 'lib/dry/validation/message.rb', line 84

def base?
  @base ||= path.compact.empty?
end

#to_sString

Dump error to a string

Returns:

  • (String)


93
94
95
# File 'lib/dry/validation/message.rb', line 93

def to_s
  text
end