Last active
September 25, 2017 05:58
-
-
Save cherring/9a27643946b6d31d1624567577fdacc6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ProfileValidator | |
| def self.validate(profile, scentregroup_id) | |
| profile_schema.call(profile.merge(scentregroup_id: scentregroup_id)) | |
| end | |
| def self.profile_schema | |
| required(:centre).filled | |
| required(:number_plates).each do | |
| schema do | |
| required(:plate).filled | |
| required(:registered_in).filled | |
| validate(plate_available: %i[plate]) do |plate| | |
| ### How can I use the centre attribute in here? | |
| end | |
| end | |
| end | |
| end | |
| end |
Author
Ah ok. I am a bit relieved that I was not missing something super obvious, thanks @timriley :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure you can refer to attributes outside of the sub-schema like you're hoping to.
Perhaps simplest thing is to have a data mapper that you run before calling the schema, which would copy the
centreattribute into each of thenumber_plateshashes? Then you could addrequired(:centre).filledinside that sub-schema and use thecentreattribute inside your validate block.I admit this is a bit awkward, but it'd get the job done here, at least.
I'd encourage you to file this as an issue on the GitHub repo, though. We're going to put our attention back onto dry-validation at some point before too long, and getting this as an issue here would at least mean we can consider this use case :)