lib/dry/schema/compiler.rb in dry-schema-0.1.1 vs lib/dry/schema/compiler.rb in dry-schema-0.2.0
- old
+ new
@@ -1,6 +1,7 @@
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
@@ -12,9 +13,25 @@
# @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