Sha256: 260d4458d71b537a3051b5b5d2b2f865d389096896342261e8c1bb5dc43c821b

Contents?: true

Size: 1.3 KB

Versions: 12

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require "dry/logic/rule_compiler"
require "dry/schema/namespaced_rule"
require "dry/schema/predicate_registry"

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 supports?(predicate)
        predicates.key?(predicate)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dry-schema-1.8.0 lib/dry/schema/compiler.rb
dry-schema-1.7.1 lib/dry/schema/compiler.rb
dry-schema-1.7.0 lib/dry/schema/compiler.rb
dry-schema-1.6.2 lib/dry/schema/compiler.rb
dry-schema-1.6.1 lib/dry/schema/compiler.rb
dry-schema-1.6.0 lib/dry/schema/compiler.rb
dry-schema-1.5.6 lib/dry/schema/compiler.rb
dry-schema-1.5.5 lib/dry/schema/compiler.rb
dry-schema-1.5.4 lib/dry/schema/compiler.rb
dry-schema-1.5.3 lib/dry/schema/compiler.rb
dry-schema-1.5.2 lib/dry/schema/compiler.rb
dry-schema-1.5.1 lib/dry/schema/compiler.rb