Sha256: 8cfa018b900f1d57a7e95b92c3d214e0ef4398614b1747955ab1974801e8cf5c

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

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

1 entries across 1 versions & 1 rubygems

Version Path
dry-schema-0.2.0 lib/dry/schema/compiler.rb