Class: Dry::Schema::Message
- Inherits:
-
Object
- Object
- Dry::Schema::Message
- Extended by:
- Initializer
- Defined in:
- lib/dry/schema/message.rb,
lib/dry/schema/message/or.rb,
lib/dry/schema/extensions/hints.rb,
lib/dry/schema/message/or/abstract.rb,
lib/dry/schema/message/or/multi_path.rb,
lib/dry/schema/message/or/single_path.rb
Overview
Hint-specific Message extensions
Direct Known Subclasses
Defined Under Namespace
Modules: Or
Instance Attribute Summary collapse
-
#args ⇒ Array
readonly
Optional list of arguments used by the predicate.
-
#input ⇒ Object
readonly
The input value.
-
#meta ⇒ Hash
readonly
Arbitrary meta data.
-
#path ⇒ String
readonly
Path to the value.
-
#predicate ⇒ Symbol
readonly
Predicate identifier that was used to produce a message.
-
#text ⇒ String
readonly
Message text representation created from a localized template.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
private
See which message is higher in the hierarchy.
- #_path ⇒ Object private
-
#dump ⇒ String, Hash
(also: #to_s)
Dump the message to a representation suitable for the message set hash.
-
#eql?(other) ⇒ Boolean
private
See if another message is the same.
- #hint? ⇒ Boolean private
-
#to_h ⇒ Hash
Dump the message into a hash.
- #to_or(root) ⇒ Object private
Instance Attribute Details
#args ⇒ Array (readonly)
Optional list of arguments used by the predicate
33 |
# File 'lib/dry/schema/message.rb', line 33 option :args, default: proc { EMPTY_ARRAY } |
#input ⇒ Object (readonly)
The input value
38 |
# File 'lib/dry/schema/message.rb', line 38 option :input |
#meta ⇒ Hash (readonly)
Arbitrary meta data
43 |
# File 'lib/dry/schema/message.rb', line 43 option :meta, optional: true, default: proc { EMPTY_HASH } |
#path ⇒ String (readonly)
Path to the value
23 |
# File 'lib/dry/schema/message.rb', line 23 option :path |
#predicate ⇒ Symbol (readonly)
Predicate identifier that was used to produce a message
28 |
# File 'lib/dry/schema/message.rb', line 28 option :predicate |
#text ⇒ String (readonly)
Message text representation created from a localized template
18 |
# File 'lib/dry/schema/message.rb', line 18 option :text |
Instance Method Details
#<=>(other) ⇒ Object
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.
See which message is higher in the hierarchy
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/dry/schema/message.rb', line 92 def <=>(other) l_path = _path r_path = other._path unless l_path.same_root?(r_path) raise ArgumentError, "Cannot compare messages from different root paths" end l_path <=> r_path end |
#_path ⇒ Object
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.
104 105 106 |
# File 'lib/dry/schema/message.rb', line 104 def _path @_path ||= Path[path] end |
#dump ⇒ String, Hash Also known as: to_s
Dump the message to a representation suitable for the message set hash
50 51 52 |
# File 'lib/dry/schema/message.rb', line 50 def dump @dump ||= .empty? ? text : {text: text, **} end |
#eql?(other) ⇒ Boolean
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.
See if another message is the same
If a string is passed, it will be compared with the text
77 78 79 |
# File 'lib/dry/schema/message.rb', line 77 def eql?(other) other.is_a?(String) ? text == other : super end |
#hint? ⇒ Boolean
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.
38 39 40 |
# File 'lib/dry/schema/extensions/hints.rb', line 38 def hint? false end |
#to_h ⇒ Hash
Dump the message into a hash
The hash will be deeply nested if the path’s size is greater than 1
64 65 66 |
# File 'lib/dry/schema/message.rb', line 64 def to_h @to_h ||= _path.to_h(dump) end |
#to_or(root) ⇒ Object
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.
82 83 84 85 86 87 |
# File 'lib/dry/schema/message.rb', line 82 def to_or(root) clone = dup clone.instance_variable_set("@path", path - root.to_a) clone.instance_variable_set("@_path", nil) clone end |