These are chat archives for dry-rb/chat

22nd
Jun 2016
David Strauß
@stravid
Jun 22 2016 06:33

Good morning everyone! My Ruby skills fail me when I try to pass along a methods block to Dry::Validation.Form. All I get is a validation.rb:24:ininstance_exec': no block given (LocalJumpError)` error.

My attempt to use dry-validation: https://gist.github.com/stravid/a88bbdbf0a1043b24eeb065a957d9776

Piotr Solnica
@solnic
Jun 22 2016 07:01
@stravid you use schema.call while this method expecte a block. Either use @schema.call or tweak the method to detect if a block was passed or not and either return existing schema or set one up
David Strauß
@stravid
Jun 22 2016 07:13
Argh, I knew it was something obvious. Thanks for spotting it @solnic
Truc Nguyen
@trucntt
Jun 22 2016 08:59
hi all, any guys can help me
schema = Dry::Validation.Form do
configure { config.input_processor = :sanitizer }
key(:receiver).schema do
optional(:filter_ids).required(:array?)
end
end
I am try to use optional with required(:array?), but this doesn't work
this is work fine for optional with required(:str? or :int?)
Hannes Nevalainen
@kwando
Jun 22 2016 09:03
@trucntt try
optional(:filter_ids).each(:int?)
(if your filter ids is integers)
Truc Nguyen
@trucntt
Jun 22 2016 09:06
thanks @kwando , you save my life :)
Oskar Szrajer
@gotar
Jun 22 2016 09:49
@timriley I add some comments of problems I found with generator
Tim Riley
@timriley
Jun 22 2016 09:54
Thanks @gotar :)
Oskar Szrajer
@gotar
Jun 22 2016 09:55
plus you still generate commands, and not repo (if you use code from master) commands are not needed, maybe in that place some basic repo with schema in relation and commands graph
ps great job !
Tim Riley
@timriley
Jun 22 2016 09:55
@gotar yeah, I was thinking it’d still be helpful to have that directory present for people who do need custom command classes still.
Otherwise you can just choose to remove it.
Oskar Szrajer
@gotar
Jun 22 2016 10:00
those generator are just in time, today I have my workshop session and looks like they will end with generating everything we learn in one sec using provided generator
thx a lot ;]
Tim Riley
@timriley
Jun 22 2016 10:00
haha, nice!
I’ll release it all within the next few hours.
Oskar Szrajer
@gotar
Jun 22 2016 10:00
without proper intruduction it will be just WTF
Tim Riley
@timriley
Jun 22 2016 10:01
All just in time for RedDotRubyConf :sweat_smile:
Oskar Szrajer
@gotar
Jun 22 2016 10:01
great hope there will be video
share a link ;]
Tim Riley
@timriley
Jun 22 2016 10:01
There should be, hopefully. Not sure how quickly it’s released though.
Oskar Szrajer
@gotar
Jun 22 2016 10:03
yeap as always they need 2-3 weeks avg to post them from any conf
Oskar Szrajer
@gotar
Jun 22 2016 15:03
Anyone have any example of dynamicly generated dry-v schema? Client can create dynamic form in UI, and check there constrains for those form, like did those field is required or min size is 3 for exmaple?
Piotr Solnica
@solnic
Jun 22 2016 15:10
yeah you can build rule ast programmaticaly
you can have a base schema and dynamically inject additional rules too
things are pretty flexible
Oskar Szrajer
@gotar
Jun 22 2016 15:11
any example somewhere?
although that would create a new schema object
if you have a schema already and you’d like to extend it dynamically
Piotr Solnica
@solnic
Jun 22 2016 15:17
you need to do schema.with(rules: array_with_rule_objects)
huh that’s probably outdated ;/
how complex are those dynamic rules?
Oskar Szrajer
@gotar
Jun 22 2016 15:18
can be very complex. Depend how user define form (he can define almost anything in UI)
pow pow pow!
Oskar Szrajer
@gotar
Jun 22 2016 15:22
nice, 30 min before workshops
;D
just in time
Tim Riley
@timriley
Jun 22 2016 15:22
even better!
Piotr Solnica
@solnic
Jun 22 2016 15:28
@gotar how are they represented?
@timriley wow :clap:
Oskar Szrajer
@gotar
Jun 22 2016 15:41
represented?
Piotr Solnica
@solnic
Jun 22 2016 15:43
yes, how the data structures look like
Oskar Szrajer
@gotar
Jun 22 2016 15:46
its a tool for client to generate form automaticaly, he can define multi level form, with any field (any type) with any validation
it's a tool for building forms
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 22 2016 17:50
@timriley when you have some time please checkout my comment on dry-result_matcher
Aditya Tiwari
@aditya01933
Jun 22 2016 19:00
How can i perform this validation ?
has_many :members
has_many :accounts, through: :members
validates :accounts, :length => { :minimum => 1 }
Ralf Schmitz Bongiolo
@mrbongiolo
Jun 22 2016 19:45
you might do something like this: required(:accounts).filled(min_size?: 1), but remember this will be done with your params and not with an AR association. Basically it will check that your form also submitted an array of accounts with atleast one account.
Piotr Solnica
@solnic
Jun 22 2016 19:51
required(:accounts).filled(:array?, min_size?: 1) otherwise a string would pass too
or hash
or whatever that has size
Fran Worley
@fran-worley
Jun 22 2016 20:55
@solnic is there a way to define a types schema and then reopen keys for business logic? (Or a plan to make that possible) ?
Piotr Solnica
@solnic
Jun 22 2016 20:56
@fran-worley you mean define basic type-safety checks and then separately business-specific rules?
Fran Worley
@fran-worley
Jun 22 2016 21:00
Yeah
Fran Worley
@fran-worley
Jun 22 2016 21:13
Or some kind of find or create system with rules I.e if a rule exists in the schema with the same key/id then append to it otherwise create a new one.
Piotr Solnica
@solnic
Jun 22 2016 22:38
Uhm that would be weird. Why would you want to create a business rule w/o basic type safety?