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

Passing predicates to a constrained type builder #179

Closed
faucct opened this issue Feb 28, 2017 · 3 comments
Closed

Passing predicates to a constrained type builder #179

faucct opened this issue Feb 28, 2017 · 3 comments

Comments

@faucct
Copy link

faucct commented Feb 28, 2017

Hello, if I want to create a constrained type with a custom predicate then I have to register it inside Dry::Logic::Predicates as the type builder expects it to be found there - https://github.com/dry-rb/dry-types/blob/9bf72c8/lib/dry/types/constraints.rb.
It would be cool to make it possible passing unregistered predicates, like this - Dry::Types::Strict::String.constrained(IpAddress::Predicate => true)

@flash-gordon
Copy link
Member

This is now possible using the case? predicate from dry-logic: https://github.com/dry-rb/dry-logic/blob/master/CHANGELOG.md#v042-to-be-released
Anything that responds to === can be used, including strings, numbers, classes, ranges, regexes, and even procs. Does it suit you?
/cc @solnic did you know? :) I'd call it the predicate of last resort lol

@faucct
Copy link
Author

faucct commented Jun 22, 2017

I didn't know that procs respond to ===. I guess it solves the problem. Thanks.

@faucct faucct closed this as completed Jun 22, 2017
@solnic
Copy link
Member

solnic commented Jun 22, 2017 via email

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

3 participants