Class: Dry::Validation::Message
- Inherits:
-
Schema::Message
- Object
- Schema::Message
- Dry::Validation::Message
- Defined in:
- lib/dry/validation/message.rb
Overview
Message message
Direct Known Subclasses
Defined Under Namespace
Classes: Localized
Instance Attribute Summary collapse
-
#meta ⇒ Hash
readonly
Optional hash with meta-data.
-
#path ⇒ Array<Symbol, Integer>
readonly
The path to the value with the error.
-
#text ⇒ String
readonly
The error message text.
Class Method Summary collapse
-
.[](text, path, meta) ⇒ Message, Message::Localized
private
Build an error.
Instance Method Summary collapse
-
#base? ⇒ Boolean
Check if this is a base error not associated with any key.
-
#initialize(text, path:, meta: EMPTY_HASH) ⇒ Message
constructor
private
Initialize a new error object.
-
#to_s ⇒ String
Dump error to a string.
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
rubocop: disable Lint/MissingSuper
74 75 76 77 78 |
# File 'lib/dry/validation/message.rb', line 74 def initialize(text, path:, meta: EMPTY_HASH) @text = text @path = Array(path) @meta = end |
Instance Attribute Details
#meta ⇒ Hash (readonly)
Optional hash with meta-data
35 36 37 |
# File 'lib/dry/validation/message.rb', line 35 def @meta end |
#path ⇒ Array<Symbol, Integer> (readonly)
The path to the value with the error
28 29 30 |
# File 'lib/dry/validation/message.rb', line 28 def path @path end |
#text ⇒ String (readonly)
The error message 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, ) klass = text.respond_to?(:call) ? Localized : Message klass.new(text, path: path, meta: ) end |
Instance Method Details
#base? ⇒ Boolean
Check if this is a base error not associated with any key
86 87 88 |
# File 'lib/dry/validation/message.rb', line 86 def base? @base ||= path.compact.empty? end |
#to_s ⇒ String
Dump error to a string
95 96 97 |
# File 'lib/dry/validation/message.rb', line 95 def to_s text end |