module Dry::Schema::Extensions::Hints::MessageCompilerMethods

Adds support for processing [:hint, …] nodes produced by dry-logic

@api private

Constants

HINT_OTHER_EXCLUSION
HINT_TYPE_EXCLUSION

Attributes

hints[R]

@api private

Public Class Methods

new(*, **) click to toggle source

@api private

Calls superclass method
# File lib/dry/schema/extensions/hints/message_compiler_methods.rb, line 22
def initialize(*, **)
  super
  @hints = @options.fetch(:hints, true)
end

Public Instance Methods

exclude?(messages, opts) click to toggle source

@api private rubocop: disable Metrics/AbcSize rubocop: disable Metrics/PerceivedComplexity rubocop: disable Metrics/CyclomaticComplexity

# File lib/dry/schema/extensions/hints/message_compiler_methods.rb, line 41
def exclude?(messages, opts)
  Array(messages).all? do |msg|
    hints = opts.hints.reject { |h|
      msg.eql?(h) || h.predicate.eql?(:filled?)
    }

    key_failure = opts.key_failure?(msg.path)
    predicate = msg.predicate

    (HINT_TYPE_EXCLUSION.include?(predicate) && !key_failure) ||
      (msg.predicate == :filled? && key_failure) ||
      (!key_failure && HINT_TYPE_EXCLUSION.include?(predicate) &&
        !hints.empty? && hints.any? { |hint| hint.path == msg.path }) ||
      HINT_OTHER_EXCLUSION.include?(predicate)
  end
end
filter(messages, opts) click to toggle source

@api private

# File lib/dry/schema/extensions/hints/message_compiler_methods.rb, line 33
def filter(messages, opts)
  Array(messages).flatten.map { |msg| msg unless exclude?(msg, opts) }.compact.uniq
end
hints?() click to toggle source

@api private

# File lib/dry/schema/extensions/hints/message_compiler_methods.rb, line 28
def hints?
  hints.equal?(true)
end
message_type(options) click to toggle source

@api private

# File lib/dry/schema/extensions/hints/message_compiler_methods.rb, line 62
def message_type(options)
  options[:message_type].equal?(:hint) ? Hint : Message
end
visit_each(_node, _opts) click to toggle source

@api private

# File lib/dry/schema/extensions/hints/message_compiler_methods.rb, line 81
def visit_each(_node, _opts)
  # TODO: we can still generate a hint for elements here!
  []
end
visit_hint(node, opts) click to toggle source

@api private

# File lib/dry/schema/extensions/hints/message_compiler_methods.rb, line 67
def visit_hint(node, opts)
  if hints?
    filter(visit(node, opts.(message_type: :hint)), opts)
  end
end
visit_predicate(node, opts) click to toggle source

@api private

Calls superclass method
# File lib/dry/schema/extensions/hints/message_compiler_methods.rb, line 74
def visit_predicate(node, opts)
  message = super
  opts.current_messages << message
  message
end