These are chat archives for dry-rb/chat

2nd
Aug 2016
Dave Myron
@contentfree
Aug 02 2016 00:55
Is there a way to get the name of the current attribute inside a custom predicate? Say I have a custom predicate (unique?) and a rule required(:name) { unique?(scope: :company_id) }. I need to know the name of the property so I can do the unique check in the database, but unless I change my usage to required(:name) { unique?(:name, scope: :company_id) } I can't seem to find a way to get the name of the required field currently being validated. Ideas?
Darcy Laycock
@Sutto
Aug 02 2016 01:08
Does anyone have a gyde for migrating from virtus to dry-types? (if that even makes sense)
@solnic btw - ended up going very far down the rabbit hole, and stopped because I realise for our use case json-schema made sense
because 99% of the time we’re dealing with the data it’s in json
Tim Riley
@timriley
Aug 02 2016 01:25
@contentfree I don’t believe you can get the name of the current attribute inside a predicate, no. If your uniqueness check needs to have some extra data provided, then the best approach would be to pass that data inside your validation rule
required(:something).filled(unique?: :for_some_name) or something like that
@Sutto sorry, I haven’t done that before. I do know that virtus and dry-types are not 1:1 feature matches
so some things may not translate in a direct way
Darcy Laycock
@Sutto
Aug 02 2016 01:26
hey @timriley
yehp, I figured that is the case - I think most of our features should exist, just need to work out what is missing :)
Tim Riley
@timriley
Aug 02 2016 01:28
right :)
Piotr Solnica
@solnic
Aug 02 2016 08:44
@Sutto json-schema?
Piotr Solnica
@solnic
Aug 02 2016 10:23
@Sutto also, what kind of rabbit hole, if I may ask? :)
Piotr Solnica
@solnic
Aug 02 2016 10:51
@Sutto re virtus vs dry-types, you gotta tell me how you use virtus