Class: Dry::Schema::MessageCompiler::VisitorOpts Private

Inherits:
Hash
  • Object
show all
Defined in:
lib/dry/schema/message_compiler/visitor_opts.rb

Overview

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

Optimized option hash used by visitor methods in message compiler

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.newObject

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
17
18
19
20
# File 'lib/dry/schema/message_compiler/visitor_opts.rb', line 14

def self.new
  opts = super
  opts[:path] = EMPTY_ARRAY
  opts[:message_type] = :failure
  opts[:current_messages] = EMPTY_ARRAY.dup
  opts
end

Instance Method Details

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



28
29
30
# File 'lib/dry/schema/message_compiler/visitor_opts.rb', line 28

def call(other)
  merge(other.update(path: [*path, *other[:path]]))
end

#current_messagesObject

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.



50
51
52
# File 'lib/dry/schema/message_compiler/visitor_opts.rb', line 50

def current_messages
  self[:current_messages]
end

#dup(current_messages = EMPTY_ARRAY.dup) ⇒ 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.



32
33
34
35
36
# File 'lib/dry/schema/message_compiler/visitor_opts.rb', line 32

def dup(current_messages = EMPTY_ARRAY.dup)
  opts = super()
  opts[:current_messages] = current_messages
  opts
end

#failuresObject

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.



42
43
44
# File 'lib/dry/schema/message_compiler/visitor_opts.rb', line 42

def failures
  current_messages.reject(&:hint?)
end

#hintsObject

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.



46
47
48
# File 'lib/dry/schema/message_compiler/visitor_opts.rb', line 46

def hints
  current_messages.select(&:hint?)
end

#key_failure?(path) ⇒ 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)


38
39
40
# File 'lib/dry/schema/message_compiler/visitor_opts.rb', line 38

def key_failure?(path)
  failures.any? { |f| f.path == path && f.predicate.equal?(:key?) }
end

#pathObject

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.



23
24
25
# File 'lib/dry/schema/message_compiler/visitor_opts.rb', line 23

def path
  self[:path]
end