Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Mikhail Slyusarev
@mikhailvs
yeah, that's what I'd do if I felt super strongly about it
Piotr Solnica
@solnic
it’s actually not coupled, we translate generic result object into whatever we want, but since generating string messages is what most people need, it’s been baked into the library
I just made it work with plain YAML because some times you may want to skip i18n as a dependency
Mikhail Slyusarev
@mikhailvs
Well when you create a custom predicate for a schema it seems like there's at least a logical coupling of its definition and the error message it could generate
Piotr Solnica
@solnic
you can still apply that predicate w/o generating a message
messages are generated only when you ask for them
Mikhail Slyusarev
@mikhailvs
as in, when you call .messages?
Piotr Solnica
@solnic
right, or in 0.10.0 errors
Mikhail Slyusarev
@mikhailvs
that makes sense
Piotr Solnica
@solnic
irb(main):004:0> Dry::Validation.Schema { required(:num).value(:int?) }.(num: 'not num').results[0].ast
=> [:key, [:num, [:predicate, [:int?, [[:input, “not num”]]]]]]
^^ here’s a result AST, gives you all info you need to generate whatever you want from it
Mikhail Slyusarev
@mikhailvs
well in my case I do need the message and I'm getting Dry::Validation::MissingMessageError if there isn't one. I think since my schema is in its own file/module it's fine to just put the messages for the custom stuff into the configure block
Piotr Solnica
@solnic
yep, as I said, if you like it, just do it :)
Mikhail Slyusarev
@mikhailvs
fair enough. in any case, separating the schema definition (sans predicate implementation) into its own file makes it sort of like a configuration file anyway
i just dont want to feel bad about what i'm doing... :P
Piotr Solnica
@solnic
it’s gonna be easy to move them to a yaml config when you feel like they make schema defs messy :)
Mikhail Slyusarev
@mikhailvs
i guess my problem is that i'd have to load the file each time i define a schema...
would doing Dry::Validation::Messages.default.merge!(...) one time on app init work?
nvm, doesnt look like theres a merge! implemented
Piotr Solnica
@solnic
Alexander Gräfe
@rickenharp
Is there a way to debug rules in dry-validations? I'm trying to find out what values are actually passed to the rule, but using puts inside the rule leads to +puts+ is not a valid predicate name
Mikhail Slyusarev
@mikhailvs
where in the definition are you using puts?
Alexander Gräfe
@rickenharp
rule(valid_blockname: [:ist_blockname, :name]) do |ist_blockname, name|
  puts ist_blockname
end
Mikhail Slyusarev
@mikhailvs
you should try Kernel.puts
or ::Kernel.puts
Alexander Gräfe
@rickenharp
That works perfectly, thanks!
Alexander Gräfe
@rickenharp
Is it possible to model this in dry-v? first_name and last_name must be filled. Unless blockname is true, in which case first_name must not be filled.
Nikita Shilnikov
@flash-gordon
@solnic I bet this is not :) looking at it
I think before(:all) { load_extension } is a bad approach, should be reworked in the same way as in dry-t
Luca Guidi
@jodosha
@solnic @flash-gordon probably new dry-logic broke rom-sql build (master) See https://gist.github.com/jodosha/55651fe8033477cba882c2af17ee8c9a.
@solnic I confirm that picking dry-types (master) in Gemfile fixes the problem. :)
Benjamin Klotz
@tak1n

@solnic @flash-gordon just updated dry-v on one of our gems and got the same problem :)

https://gist.github.com/tak1n/79c180ac09fbacbae0f432169798233b

Nikita Shilnikov
@flash-gordon
@tak1n have you tried to update dry-logic as well? And, probably, dry-t, dunno
Benjamin Klotz
@tak1n
gem 'dry-struct', github: 'dry-rb/dry-struct'
gem 'dry-validation', github: 'dry-rb/dry-validation'
gem 'dry-types', github: 'dry-rb/dry-types'
putting this into Gemfile fixes the problem
yea I tried to update everything bundle update and tried it explicitly on some gems bundle update --source dry-validation etc
I mean actually I should just need to update dry-v as I'm just using dry-v (and dry-v uses those other gems internally) :)
Egor Lynko
@flexoid

There's also a WIP feature in dry-validation where you can infer validations from a struct definition. It's been in an experimental phase since a couple of releases but we're gonna make it robust prior 1.0.0. (by @solnic)

Is it possible to use this feature, or at lease try it now?

Piotr Solnica
@solnic
@jodosha yeah I know, I need to update/release types and validation
Luca Guidi
@jodosha
@solnic No worries man. Just wanted you and the rest of the team to be aware of it.
Piotr Solnica
@solnic
hmm folks who want to stay on dry-v/t 0.9/0.8 will have to pin dry-l to 0.3.0
I hope nobody is doing bundle update :laughing:
Piotr Solnica
@solnic
@flash-gordon looks like types/struct are green on CI :)
Nikita Shilnikov
@flash-gordon
@solnic should be :) tbh the changes were small enough
Piotr Solnica
@solnic
@flash-gordon pls merge dry-v pr when it’s green
Nikita Shilnikov
@flash-gordon
k
Kiril Dokh
@dsounded
@solnic What’s about dry-validation ?
is custom validation done for now ?
Piotr Solnica
@solnic
@dsounded wdym?
Kiril Dokh
@dsounded
I mean can I write custom code inside rules ?
Piotr Solnica
@solnic
@dsounded oh sorry, I’ve read it as “gone” :laughing: yes, they are done in master, I’ll push a release today
Kiril Dokh
@dsounded
Wow, glad to hear :)
@flash-gordon WDYT if value_or should be in Try monad as well ?