-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
import_predicates_as_macros: included_in?, format?, size? issues #608
Comments
Just ran into these same issues with |
#610 adds missing About the other two, the issue is that they are related to predicates expecting an array (or range) as argument. It hasn't straightforward solution. Macro argument(s) are forwarded to the predicate method, and we don't have any way to tell whether it expects an array or an unitary item. I see three options:
rule('hogwarts_house.head').validate(size?: [1..255])
rule('hogwarts_house.common_room.location').validate(included_in?: [['tower', 'underground']])
|
@waiting-for-dev that's OK, it's always worked like that, going back to dry-validation |
@waiting-for-dev ...no wait, sorry - it did not work like that in dry-validation |
Currently, a predicate can be of three kinds:
The last two are problematic when used with rule(:age).validate(gt: 18) # => `macro.args` is `[18]`
rule(:age).validate(included_in: [18, 21]) # => `macro.args` is `[18, 21]` In the As ruby is a dynamically typed language, there is no way to know whether the expected argument is an array or not. Currently, when arguments are dispatched they are splatted, so when you provide an array like in |
In the case of |
Maybe we should:
|
I bet that is the solution we're looking for |
The referenced PR should fix the issue here with About |
For
included_in?
andsize?
passing an array of integers/strings not working but it works when just one value passed or with predicates which do not require arrays)included_in?
size?
This predicate is just returning error.
format?
The text was updated successfully, but these errors were encountered: