Class: Dry::Schema::Message::Or::SinglePath
- Defined in:
- lib/dry/schema/message/or/single_path.rb,
lib/dry/schema/extensions/hints.rb
Overview
A message type used by OR operations with the same path
Instance Attribute Summary collapse
- #_path ⇒ Object readonly private
- #messages ⇒ Object readonly private
- #path ⇒ Object readonly private
Attributes inherited from Abstract
Instance Method Summary collapse
-
#dump ⇒ String
(also: #to_s)
Dump a message into a string.
- #hint? ⇒ Boolean private
-
#initialize(*args, messages) ⇒ SinglePath
constructor
private
A new instance of SinglePath.
- #to_a ⇒ Object private
-
#to_h ⇒ String
Dump an ‘or` message into a hash.
- #to_or(root) ⇒ Object private
Constructor Details
#initialize(*args, messages) ⇒ SinglePath
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.
Returns a new instance of SinglePath.
21 22 23 24 25 26 27 |
# File 'lib/dry/schema/message/or/single_path.rb', line 21 def initialize(*args, ) super(*args.map { [_1].flatten }) @messages = = left.first @path = .path @_path = ._path end |
Instance Attribute Details
#_path ⇒ Object (readonly)
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.
15 16 17 |
# File 'lib/dry/schema/message/or/single_path.rb', line 15 def _path @_path end |
#messages ⇒ Object (readonly)
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.
18 19 20 |
# File 'lib/dry/schema/message/or/single_path.rb', line 18 def @messages end |
#path ⇒ Object (readonly)
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.
12 13 14 |
# File 'lib/dry/schema/message/or/single_path.rb', line 12 def path @path end |
Instance Method Details
#dump ⇒ String Also known as: to_s
Dump a message into a string
Both sides of the message will be joined using translated value under ‘dry_schema.or` message key
39 40 41 |
# File 'lib/dry/schema/message/or/single_path.rb', line 39 def dump @dump ||= [*left, *right].map(&:dump).join(" #{[:or]} ") 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.
24 25 26 |
# File 'lib/dry/schema/extensions/hints.rb', line 24 def hint? false end |
#to_a ⇒ 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.
56 57 58 |
# File 'lib/dry/schema/message/or/single_path.rb', line 56 def to_a @to_a ||= [*left, *right] end |
#to_h ⇒ String
Dump an ‘or` message into a hash
51 52 53 |
# File 'lib/dry/schema/message/or/single_path.rb', line 51 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.
61 62 63 64 65 66 67 |
# File 'lib/dry/schema/message/or/single_path.rb', line 61 def to_or(root) to_ored = [left, right].map do |msgs| msgs.map { _1.to_or(root) } end self.class.new(*to_ored, ) end |