Class: Dry::Schema::Message::Or::SinglePath

Inherits:
Abstract
  • Object
show all
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

Attributes inherited from Abstract

#left, #right

Instance Method Summary collapse

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.



23
24
25
26
27
28
29
# File 'lib/dry/schema/message/or/single_path.rb', line 23

def initialize(*args, messages)
  super(*args.map { [_1].flatten })
  @messages = messages
  message = left.first
  @path = message.path
  @_path = message._path
end

Instance Attribute Details

#_pathObject (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.



17
18
19
# File 'lib/dry/schema/message/or/single_path.rb', line 17

def _path
  @_path
end

#messagesObject (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.



20
21
22
# File 'lib/dry/schema/message/or/single_path.rb', line 20

def messages
  @messages
end

#pathObject (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.



14
15
16
# File 'lib/dry/schema/message/or/single_path.rb', line 14

def path
  @path
end

Instance Method Details

#dumpString 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

Returns:

  • (String)

See Also:



41
42
43
# File 'lib/dry/schema/message/or/single_path.rb', line 41

def dump
  @dump ||= [*left, *right].map(&:dump).join(" #{messages[: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.

Returns:

  • (Boolean)


28
29
30
# File 'lib/dry/schema/extensions/hints.rb', line 28

def hint?
  false
end

#to_aObject

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.



58
59
60
# File 'lib/dry/schema/message/or/single_path.rb', line 58

def to_a
  @to_a ||= [*left, *right]
end

#to_hString

Dump an `or` message into a hash

Returns:

  • (String)

See Also:



53
54
55
# File 'lib/dry/schema/message/or/single_path.rb', line 53

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.



63
64
65
66
67
68
69
# File 'lib/dry/schema/message/or/single_path.rb', line 63

def to_or(root)
  to_ored = [left, right].map do |msgs|
    msgs.map { _1.to_or(root) }
  end

  self.class.new(*to_ored, messages)
end