Sha256: 89774e254ff30423aa27196cd255eb49d5b8d3d3ef0ae3ae475cf29e1b8934bd

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Dry
  module Schema
    # Extended rule compiler used internally by the DSL
    #
    # @api private
    class Compiler < Logic::RuleCompiler
      # Builds a default compiler instance with custom predicate registry
      #
      # @return [Compiler]
      #
      # @api private
      def self.new(predicates = PredicateRegistry.new)
        super
      end

      # @api private
      def visit_and(node)
        super.with(hints: false)
      end

      # Build a special rule that will produce namespaced failures
      #
      # This is needed for schemas that are namespaced and they are
      # used as nested schemas
      #
      # @param [Array] node
      # @param [Hash] _opts Unused
      #
      # @return [NamespacedRule]
      #
      # @api private
      def visit_namespace(node, _opts = EMPTY_HASH)
        namespace, rest = node
        NamespacedRule.new(namespace, visit(rest))
      end

      # Return true if a given predicate is supported by this compiler
      #
      # @param [Symbol] predicate
      #
      # @return [Boolean]
      #
      # @api private
      def support?(predicate)
        predicates.key?(predicate)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
dry-schema-1.13.3 lib/dry/schema/compiler.rb
dry-schema-1.13.2 lib/dry/schema/compiler.rb
dry-schema-1.13.1 lib/dry/schema/compiler.rb
dry-schema-1.13.0 lib/dry/schema/compiler.rb
dry-schema-1.12.0 lib/dry/schema/compiler.rb
dry-schema-1.11.3 lib/dry/schema/compiler.rb
dry-schema-1.11.2 lib/dry/schema/compiler.rb
dry-schema-1.11.1 lib/dry/schema/compiler.rb
dry-schema-1.11.0 lib/dry/schema/compiler.rb