High level rule validation ArgumentError

#1
Create = Dry::Validation.Schema do
  required(:template_zones).each do
    schema do
      required(:name).filled(:str?)

      optional(:validations)
      optional(:columns).maybe(:array?)

      # if columns attr is not present/empty then validations must be an array of allowed strings
      rule(is_not_table: %i(columns validations)) do |columns, validations|
        columns.none? > validations.type?(Array) & validations.each(included_in?: ["required", "numeric"])
      end
    end
  end
end

This raises ArgumentError: included_in? predicate arity is invalid. I probably didn’t understand the DSL properly. Could anyone direct me on the right path?

schema.call({ template_zones: [{ name: "my_name", validations: ["required", "invalid"] }]}).errors

I figured out that for:

rule(validations: [:columns, :validations]) do |columns, validations|
  validations.each { v.included_in?(["required, ''alphanum"]) }
end

v variable is [:name, "my_name"]. While my expectation is that it should be an element of validations - "required" and "invalid"

So it seems like each inside rule has some unexpected behaviour?
Anyway i resolved the issue using custom valiidator:

rule(validations: [:columns, :validations]) do |columns, validations|
  validations.validation_rules?
end

PS. What is the easiest way to debug my schema? If i put binding.pry inside schema it will raise ArgumentError: +binding+ is not a valid predicate name

0 Likes