Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High Level rules nested data #429

konalegi opened this issue Oct 22, 2018 · 1 comment

High Level rules nested data #429

konalegi opened this issue Oct 22, 2018 · 1 comment


Copy link

@konalegi konalegi commented Oct 22, 2018

Probably I am wrong with my code, but I wasn't able to validate nested data in high-level rules.
my code to reproduce.

I need to conditional validation for extensions array

require 'dry/validation'

A_ALLOWED_TYPES = [1,2,3,4,5]
B_ALLOWED_TYPES = [10,11,12,13,14,15]

schema = Dry::Validation.Schema do
  required(:type).filled(:str?, included_in?: %w(a b))
  required(:extensions).filled(:array?, min_size?: 1)

  rule(extensions_a: %i(type extensions)) do |type, extensions|
    type.eql?('a') > extensions.array? { each { included_in?(A_ALLOWED_TYPES) }}

  rule(extensions_b: %i(type extensions)) do |type, extensions|
    type.eql?('b') > extensions.array? { each { included_in?(B_ALLOWED_TYPES) }}

data_a = {
  type: 'a',
  extensions: [1,2,3,10]

data_b = {
  type: 'a',
  extensions: [10,11,1]

res =
p res.errors

After exection errors are empty. If I use simply predicates, like extensions.eql?([1,2,3]) it works perfectly.

Tested with dry validation 0.10.x - 0.12.x.

So the question, why it doesn't work?


This comment has been minimized.

Copy link

@solnic solnic commented Feb 5, 2019

Closing because this type of rules will be removed in 1.0.0

@solnic solnic closed this Feb 5, 2019
@solnic solnic added the wontfix label Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.