These are chat archives for dry-rb/chat

13th
Dec 2015
Lorenzo Arribas
@larribas
Dec 13 2015 16:18
Hello guys! I've been toying a bit with dry-validation and I haven't found a way to validate that a Hash has EXACTLY the keys I define in the schema (i.e no extra keys)
Am I missing it? I could try contributing something, otherwise
Krzysztof Wawer
@wafcio
Dec 13 2015 16:20
you have key method and optional method for hash keys
Lorenzo Arribas
@larribas
Dec 13 2015 16:22
yes, but take for instance the example in the IO page. If you try to validate:
schema.call(email: 'jane@doe.org', age: nil, extra_parameter: "I'm in!")
that would work, right?
Krzysztof Wawer
@wafcio
Dec 13 2015 16:23
what do you want validate ?
you can write key(:email) … , key(:age) …, optional(:extra_parameter) … if I good understand
Lorenzo Arribas
@larribas
Dec 13 2015 16:25
The thing is, I want to validate a Hash of settings, and I want the settings to be accurate so I can store them in my DB
And I don't want to store extra keys I don't use for anything
That is, I want to validate that what the client is sending me is exactly what I am asking. No more, no less
Krzysztof Wawer
@wafcio
Dec 13 2015 16:26
so if hash contains more keys you want to return error, right ?
Lorenzo Arribas
@larribas
Dec 13 2015 16:26
yep!
that's right
Krzysztof Wawer
@wafcio
Dec 13 2015 16:28
I don’t think so that it is validation part
for sure you are not able to do it by dry-validation right now
Lorenzo Arribas
@larribas
Dec 13 2015 16:30
hmm ok. don't you think it would be useful?
Krzysztof Wawer
@wafcio
Dec 13 2015 16:32
in some specific case it can be useful, but you can remove extra keys and save only keys which you want
of course it depend on your use case
but as alway you can fork dry-validation, write your feature and send pull-request
Lorenzo Arribas
@larribas
Dec 13 2015 16:42
ok. thanks!
Piotr Solnica
@solnic
Dec 13 2015 18:35
@larribas hey, it is a feature I plan to add. Right now unexpected keys are ignored but there will be feature to treat unexpected keys as a rule violation