Sha256: e5c26ddeba0873987b01ed455380cfe85ed20a1cd5432e2116b39f458c4eb693

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 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

      # 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
      #
      # @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

2 entries across 2 versions & 1 rubygems

Version Path
dry-schema-0.4.0 lib/dry/schema/compiler.rb
dry-schema-0.3.0 lib/dry/schema/compiler.rb