lib/dry/validation/schema/value.rb in dry-validation-0.7.0 vs lib/dry/validation/schema/value.rb in dry-validation-0.7.1
- old
+ new
@@ -24,20 +24,31 @@
def class
Value
end
+ def schema(other = nil, &block)
+ schema = Schema.create_class(self, other, &block)
+ hash?.and(schema)
+ end
+
def each(*predicates, &block)
- val =
+ left = array?
+
+ right =
if predicates.size > 0
- predicates
+ inferred = predicates
.reduce(Value.new) { |a, e| a.__send__(*::Kernel.Array(e)) }
+
+ create_rule([:each, inferred.to_ast])
else
- Value[name].instance_eval(&block)
+ val = Value[name].instance_eval(&block)
+
+ create_rule([:each, [:set, val.rule_ast]])
end
- rule = array?.and(create_rule([:each, val.to_ast]))
+ rule = left.and(right)
add_rule(rule) if root?
rule
end
@@ -66,14 +77,14 @@
add_check(val.with(rules: [res.with(deps: deps || [])]))
end
def confirmation
- rule = check(:"#{name}_confirmation")
- .eql?(check(name))
- .with(deps: [name])
+ conf = :"#{name}_confirmation"
- add_check(rule)
+ parent.optional(conf).maybe
+
+ rule(conf => [conf, name]) { |left, right| left.eql?(right) }
end
def value(name)
check(name, rules: rules)
end