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

Nested predicates #29

Closed
Kukunin opened this issue Feb 8, 2017 · 6 comments
Closed

Nested predicates #29

Kukunin opened this issue Feb 8, 2017 · 6 comments

Comments

@Kukunin
Copy link

Kukunin commented Feb 8, 2017

Can we build predicate which can validate attributes against nested predicates?

It'd be useful for Dry::Struct, something like:

class User < Dry::Struct
  attribute :age, Types::Strict::Int
end

Adult = User.constrained(attribute: {age: {gteq: 18}})

Of course, we can invent better DSL

@Kukunin
Copy link
Author

Kukunin commented Feb 8, 2017

A couple caveats:

  1. There is already attr? predicate
  2. what's the syntax for nested predicates? dry-types uses keys without ? sign, while dry-validates expects keys with ?.
  3. That fact, that hash or rule compiler is implemented outside of dry-logic: https://github.com/dry-rb/dry-types/blob/f618eda432bbab75a33c7a1457eb267e1ed5dac5/lib/dry/types/constraints.rb#L9, isn't it better to implement such predicate there?

@Kukunin
Copy link
Author

Kukunin commented Feb 8, 2017

  1. It'd be good to compose nested predicate failing message based on sub-predicates

@solnic
Copy link
Member

solnic commented Feb 13, 2017

There is already attr? predicate

This should be removed

what's the syntax for nested predicates?

What's a "nested predicate"?

dry-types uses keys without ? sign, while dry-validates expects keys with ?.

Yes, because constraints != validation

It'd be good to compose nested predicate failing message based on sub-predicates

Could you explain a bit more? :)

@solnic
Copy link
Member

solnic commented Feb 13, 2017

That fact, that hash or rule compiler is implemented outside of dry-logic: https://github.com/dry-rb/dry-types/blob/f618eda432bbab75a33c7a1457eb267e1ed5dac5/lib/dry/types/constraints.rb#L9, isn't it better to implement such predicate there?

This is functionality specific to dry-types. in dry-validation DSL is gazillion times more complex due to all kinds of additional features that dry-v has.

@Kukunin
Copy link
Author

Kukunin commented Feb 13, 2017

I see. probably the best way is to implement attribute: predicate in dry-struct with syntax above

@solnic
Copy link
Member

solnic commented Mar 20, 2019

I don't think we'll ever do this. Closing for now. Feel free to bring this up again on our discussion forum.

@solnic solnic closed this as completed Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants