These are chat archives for dry-rb/chat

21st
Sep 2016
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 02:19 UTC
do you guys actually use dry-rb in production?
John Backus
@backus
Sep 21 2016 02:19 UTC
We do
dry-validation and dry-types
works great
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 02:21 UTC
hmm... i've refactored a pretty big app to use dry-containers/validation/transactions but i'm feeling a bit reluctant to pull the trigger on deploying it
either way. it seems like a very cool collection of libraries
John Backus
@backus
Sep 21 2016 02:36 UTC
If you have good tests I think you should be safe although I can't vouch for containers and transactions
just lock yourself to a strict version
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 02:37 UTC
yeah... for sure
Piotr Solnica
@solnic
Sep 21 2016 02:41 UTC
@mikhailvs what’s your concern?
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 02:42 UTC
Honestly, I've only very recently stumbled upon dry-rb, and it's hard to gauge how widely it's being used. I suppose it's not a real concern though, more like curiousity.
Piotr Solnica
@solnic
Sep 21 2016 02:47 UTC
@mikhailvs it’s used on production by many people
it is unstable though, so APIs may change from time to time until we hit 1.0.0
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 03:05 UTC
Is there a way to set a message for a custom dry-validation predicate without loading a yaml file?
Piotr Solnica
@solnic
Sep 21 2016 03:08 UTC
not yet
I mean…it is possible to merge in your own messages
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 03:10 UTC
is that not recommended/
what you linked to actually seems like a pretty sane way of doing that
Piotr Solnica
@solnic
Sep 21 2016 03:11 UTC
well, I don’t like it but it doesn’t mean it’s not recommended. personally I dislike having core objects of my system cluttered with UI-related configurations
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 03:13 UTC
I can see that. I'd still feel like there's UI stuff polluting backend code with a yaml conf file though... especially with api driven apps.
Piotr Solnica
@solnic
Sep 21 2016 03:18 UTC
how come? that’s a nice separation, just like you separate html templates from objects that provide data for rendering, it’s somewhat similar here
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 03:21 UTC
I mean it's stuff that shows up on the frontend, being defined in files of the backend project.
Piotr Solnica
@solnic
Sep 21 2016 03:22 UTC
you could render them on the client side and have message templates defined there
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 03:22 UTC
I'm not saying I have a different/better approach though. But it seems like the kind of error something is, is coupled with the text description of it, and since the error is generated on the backend, it's fine for other components of it to be defined there as well.
yeah, that's what I'd do if I felt super strongly about it
Piotr Solnica
@solnic
Sep 21 2016 03:23 UTC
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
Sep 21 2016 03:26 UTC
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
Sep 21 2016 03:27 UTC
you can still apply that predicate w/o generating a message
messages are generated only when you ask for them
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 03:27 UTC
as in, when you call .messages?
Piotr Solnica
@solnic
Sep 21 2016 03:28 UTC
right, or in 0.10.0 errors
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 03:28 UTC
that makes sense
Piotr Solnica
@solnic
Sep 21 2016 03:29 UTC
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
Sep 21 2016 03:32 UTC
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
Sep 21 2016 03:32 UTC
yep, as I said, if you like it, just do it :)
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 03:34 UTC
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
Sep 21 2016 03:46 UTC
it’s gonna be easy to move them to a yaml config when you feel like they make schema defs messy :)
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 03:47 UTC
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
Sep 21 2016 05:04 UTC
Alexander Gräfe
@rickenharp
Sep 21 2016 05:57 UTC
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
Sep 21 2016 06:06 UTC
where in the definition are you using puts?
Alexander Gräfe
@rickenharp
Sep 21 2016 06:07 UTC
rule(valid_blockname: [:ist_blockname, :name]) do |ist_blockname, name|
  puts ist_blockname
end
Mikhail Slyusarev
@mikhailvs
Sep 21 2016 06:22 UTC
you should try Kernel.puts
or ::Kernel.puts
Alexander Gräfe
@rickenharp
Sep 21 2016 06:24 UTC
That works perfectly, thanks!
Alexander Gräfe
@rickenharp
Sep 21 2016 06:56 UTC
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
Sep 21 2016 08:15 UTC
@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
Sep 21 2016 08:32 UTC
@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
Sep 21 2016 11:43 UTC

@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
Sep 21 2016 11:45 UTC
@tak1n have you tried to update dry-logic as well? And, probably, dry-t, dunno
Benjamin Klotz
@tak1n
Sep 21 2016 11:47 UTC
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
Sep 21 2016 12:06 UTC

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
Sep 21 2016 12:42 UTC
@jodosha yeah I know, I need to update/release types and validation
Luca Guidi
@jodosha
Sep 21 2016 12:43 UTC
@solnic No worries man. Just wanted you and the rest of the team to be aware of it.
Piotr Solnica
@solnic
Sep 21 2016 13:02 UTC
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
Sep 21 2016 13:09 UTC
@flash-gordon looks like types/struct are green on CI :)
Nikita Shilnikov
@flash-gordon
Sep 21 2016 13:12 UTC
@solnic should be :) tbh the changes were small enough
Piotr Solnica
@solnic
Sep 21 2016 13:16 UTC
@flash-gordon pls merge dry-v pr when it’s green
Nikita Shilnikov
@flash-gordon
Sep 21 2016 13:23 UTC
k
Kiril Dokh
@dsounded
Sep 21 2016 13:42 UTC
@solnic What’s about dry-validation ?
is custom validation done for now ?
Piotr Solnica
@solnic
Sep 21 2016 14:04 UTC
@dsounded wdym?
Kiril Dokh
@dsounded
Sep 21 2016 14:05 UTC
I mean can I write custom code inside rules ?
Piotr Solnica
@solnic
Sep 21 2016 14:11 UTC
@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
Sep 21 2016 14:14 UTC
Wow, glad to hear :)
@flash-gordon WDYT if value_or should be in Try monad as well ?
Kiril Dokh
@dsounded
Sep 21 2016 14:22 UTC
Also it would be OK to implement Xor monad(right biased Either)
Nikita Shilnikov
@flash-gordon
Sep 21 2016 14:25 UTC
@dsounded re value_or this would be strange a bit. This means you're silently ignoring exception value which is usually not a good idea
if you really want to do it, you can use my_try.to_maybe.value_or
@dsounded I'll revisit supported monads in a while, when I finish the monads chapter in that haskell book ;)
John Backus
@backus
Sep 21 2016 19:30 UTC
I might be missing something obvious but is there no way on gitter to just search the dry-rb/chat room?
Nikita Shilnikov
@flash-gordon
Sep 21 2016 19:35 UTC
@backus I bet you're supposed to love new global search, one field for everything
John Backus
@backus
Sep 21 2016 19:36 UTC
:'(
But every room in gitter is a software room basically
and I want to search deduplicating schemas
Oh it actually worked alright
Maybe the gitter overlords know better
Nikita Shilnikov
@flash-gordon
Sep 21 2016 19:42 UTC
haha
Joe Van Dyk
@joevandyk
Sep 21 2016 19:50 UTC
hm, I just tried using dry-validation and I get an exception when requiring the library
Piotr Solnica
@solnic
Sep 21 2016 19:53 UTC
@joevandyk hey, sorry about that…it’s my fault, pin dry-logic to 0.3.0 for now. I’ll release new validation/types later today
Joe Van Dyk
@joevandyk
Sep 21 2016 19:53 UTC
dry-rb/dry-validation#256
ah ok
Piotr Solnica
@solnic
Sep 21 2016 19:54 UTC
I started release process yesterday and didn’t manage to finish, I’ll do it soooon
Joe Van Dyk
@joevandyk
Sep 21 2016 19:54 UTC
no worries
Joe Van Dyk
@joevandyk
Sep 21 2016 20:12 UTC
what does the validation look like for validating an array of strings?
(and then an array of strings that contain valid urls)
Piotr Solnica
@solnic
Sep 21 2016 20:15 UTC
@joevandyk required(:urls).each(:str?, :url?)
Joe Van Dyk
@joevandyk
Sep 21 2016 20:16 UTC
ah, nice. what about an validating that there's at least one image in the array?
Piotr Solnica
@solnic
Sep 21 2016 20:21 UTC
@joevandyk required(:urls).value(min_size?: 1) { each(:str?, :url?) }
unfortunately chaining doesn’t work yet, so you gotta use a block
Piotr Solnica
@solnic
Sep 21 2016 21:06 UTC
@/all hey folks! dry-validation 0.10.0 dry-types 0.9.0 and the new dry-struct 0.1.0 gems have been just released. Please do read CHANGELOGs on GitHub before upgrading :) More info coming soon on our blog!
Tim Riley
@timriley
Sep 21 2016 22:07 UTC
woooo solnic nice woooooorrrkkkk :tada:
Joe Van Dyk
@joevandyk
Sep 21 2016 22:08 UTC
how can I validate in dry-validation that a hash has string keys and string values?
Tim Riley
@timriley
Sep 21 2016 22:08 UTC
I guess you’d need to use the input macro for that
Joe Van Dyk
@joevandyk
Sep 21 2016 22:09 UTC
/home/monkey/.gem/ruby/2.2.5/gems/dry-validation-0.10.0/lib/dry/validation/schema/value.rb:1:in `require': cannot load such file -- dry/struct (LoadError)
    from /home/monkey/.gem/ruby/2.2.5/gems/dry-validation-0.10.0/lib/dry/validation/schema/value.rb:1:in `<top (required)>'
    from /home/monkey/.gem/ruby/2.2.5/gems/dry-validation-0.10.0/lib/dry/validation/schema.rb:7:in `require'
    from /home/monkey/.gem/ruby/2.2.5/gems/dry-validation-0.10.0/lib/dry/validation/schema.rb:7:in `<top (required)>'
is that expected?
Nikita Shilnikov
@flash-gordon
Sep 21 2016 22:11 UTC
oops
Joe Van Dyk
@joevandyk
Sep 21 2016 22:11 UTC
this is when requiring dry-v
Nikita Shilnikov
@flash-gordon
Sep 21 2016 22:15 UTC
@solnic I pushed a fix ^
just removed that line, I overlooked it, sorry
Joe Van Dyk
@joevandyk
Sep 21 2016 22:54 UTC
@timriley what's the input macro?
Jānis Miezītis
@janjiss
Sep 21 2016 23:08 UTC
Folks, I just wanted to say: You are awesome
Nikita Shilnikov
@flash-gordon
Sep 21 2016 23:30 UTC
:heart: