module Dry::Schema::Extensions::Hints::MessageCompilerMethods
def exclude?(messages, opts)
- Api: - private
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
def filter(messages, opts)
- Api: - private
def filter(messages, opts) Array(messages).flatten.map { |msg| msg unless exclude?(msg, opts) }.compact.uniq end
def hints?
- Api: - private
def hints? hints.equal?(true) end
def initialize(*, **)
- Api: - private
def initialize(*, **) super @hints = @options.fetch(:hints, true) end
def message_type(options)
- Api: - private
def message_type(options) options[:message_type].equal?(:hint) ? Hint : Message end
def visit_each(_node, _opts)
- Api: - private
def visit_each(_node, _opts) # TODO: we can still generate a hint for elements here! [] end
def visit_hint(node, opts)
- Api: - private
def visit_hint(node, opts) if hints? filter(visit(node, opts.(message_type: :hint)), opts) end end
def visit_predicate(node, opts)
- Api: - private
def visit_predicate(node, opts) message = super opts.current_messages << message message end