These are chat archives for dry-rb/chat

14th
Mar 2016
Kris Leech
@krisleech
Mar 14 2016 13:17

Latest dry-validations gives me an error when required.

irb(main):001:0> require 'dry-validation'
NoMethodError: undefined method `visit_String' for #<Dry::Logic::RuleCompiler:0x007fe233a0ba28>
ruby/2.2.2/gems/dry-logic-0.2.0/lib/dry/logic/rule_compiler.rb:18:in `visit'

Is this known?

dry-logic-0.2.0 -> dry-data-0.5.1 -> dry-validation-0.6.0
Piotr Solnica
@solnic
Mar 14 2016 13:18
@krisleech you need dry-types from master
both gems will be released in a couple of days
dry-data is deprecated
Kris Leech
@krisleech
Mar 14 2016 13:18
@solnic thanks
Piotr Solnica
@solnic
Mar 14 2016 13:18
as in, renamed :)
Kris Leech
@krisleech
Mar 14 2016 13:18
ah, okay - cool :)
Andy Holland
@AMHOL
Mar 14 2016 13:19
Hi @krisleech :)
Kris Leech
@krisleech
Mar 14 2016 13:21
@AMHOL hey - good to meet you the other day. Had to shoot at the end to get a train :D
Andy Holland
@AMHOL
Mar 14 2016 13:22
Yeah, Bill mentioned, I think I was outside smoking when you left, was good meeting you too
Now we need to find a conference we can all attend and get drunk afterwards :laughing:
Kris Leech
@krisleech
Mar 14 2016 13:22
ha ha - yes. Once closer to the midlands!
Andy Holland
@AMHOL
Mar 14 2016 13:23
Definitely, I'm still waiting for MancRuby :p
Kris Leech
@krisleech
Mar 14 2016 13:23
wait and wait and wait...
Andy Holland
@AMHOL
Mar 14 2016 13:25
Indeed :(
Kris Leech
@krisleech
Mar 14 2016 13:26
I remember MagRails back in the day, but the second one got canceled.
Andy Holland
@AMHOL
Mar 14 2016 13:26
Still no sign of James either
Kris Leech
@krisleech
Mar 14 2016 13:26
BritRuby, or something.
Andy Holland
@AMHOL
Mar 14 2016 13:26
Yeah, that whole thing
That was pretty annoying
Should just do an anonymous CFP, then speakers can be chosen on the merit of their talks without the whole diversity thing ever being a problem
Kris Leech
@krisleech
Mar 14 2016 13:28
Yeah, I was looking forward to it. Glad we have a few in the UK now.
Andy Holland
@AMHOL
Mar 14 2016 13:30
Yeah, I was speaking to someone a while back, she mentioned that she wanted to organise a conference on an old train on the Ale Trail
That would be cool
could you take a look and let me know your thoughts ^
Andy Holland
@AMHOL
Mar 14 2016 13:30
@solnic will do mate
Piotr Solnica
@solnic
Mar 14 2016 13:30
it’s pretty rough I gotta say, not sure yet how to organize these docs
Andy Holland
@AMHOL
Mar 14 2016 13:30
dry-types vs virtus slating your own gems :laughing:
Piotr Solnica
@solnic
Mar 14 2016 13:31
it’s how I roll
Kris Leech
@krisleech
Mar 14 2016 13:31
:D
Piotr Solnica
@solnic
Mar 14 2016 13:31
I also really count on somebody telling me this makes no sense and I don’t know what I’m talking about ;)
and that virtus is great ;)
Andy Holland
@AMHOL
Mar 14 2016 13:33
:joy:
@solnic I'll make some time tonight and work on the configuration/container docs and give feedback on types/validation if that's OK?
Piotr Solnica
@solnic
Mar 14 2016 13:35
that would be fantastic
Andy Holland
@AMHOL
Mar 14 2016 13:35
Cool
Piotr Solnica
@solnic
Mar 14 2016 13:38
I’ll be updating the docs based on feedback, I just realized I’ve got absolutely no time / energy to think how to do it, then do it and then get feedback it sucks and re-do it again, blah
Andy Holland
@AMHOL
Mar 14 2016 13:39
lol
By feedback I don't think it'll be anything to do with the structure/code samples, looks good from what I've seen so far
Michał Pietrus
@blelump
Mar 14 2016 13:47
@solnic, quick shoot:
  1. would be nice to stress a bit more about the DSL syntax itself, e.g:
    a. what is &, |, > (I believe these are 'and', 'or' and 'xor') and how are they related to && , || operators (if at all);
    b. perhaps show an comparison of using '>' vs 'then'
  2. How to define custom validation logic – as a dumb person, in my dictionary it's, among other things, a 'conditional validation', but I'm open for a more formal name from your point of view :-) . Anyway, the more people will start using dry-v, it is likely the more will ask such questions.
  3. what's 'maybe' macro and why one should bother, e.g. whats the difference between maybe vs optional;
  4. what's when and how to use it
ad 4: I meant with
Piotr Solnica
@solnic
Mar 14 2016 13:48
@blelump thanks, I’ll be adding a section about predicate operators and macros
Michał Pietrus
@blelump
Mar 14 2016 13:51
  1. I'm missing a validation schema with a custom type too :-)
  2. validate coercions ?
uhm , it supposed to be 5 and 6, but gitter seems to be smarter
Piotr Solnica
@solnic
Mar 14 2016 13:55
damn, so much is missing :)
otoh, such features wow :D
Michał Pietrus
@blelump
Mar 14 2016 13:56
:-)
another thing would be to stress the old vs new syntax, e.g: key(:duration_in_months, &:filled?) vs. key(:duration_in_months).required and perhaps a section about how to migrate to dry-v 0.7 from 0.x
@solnic , 0.7 really kicks ass in case of new features :-)
Piotr Solnica
@solnic
Mar 14 2016 14:01
both still works, macros are there to remove boilerplate but blocks still work
so key(:age).required(:int?) == key(:age) { filled? & int? }
Michał Pietrus
@blelump
Mar 14 2016 14:04
sure , so there might be at least a paragraph about macros :-)
Piotr Solnica
@solnic
Mar 14 2016 14:06
there will be a whole section
under Basics
Michał Pietrus
@blelump
Mar 14 2016 14:06
:+1:
Shaun Hannah
@hooptie45
Mar 14 2016 14:20
I'm curious, is there anything in particular that makes dry-types so fast?
Andy Holland
@AMHOL
Mar 14 2016 14:21
@/all @solnic and I have been talking about renaming the Github organisation to dry-rb to be consistent with rom-rb, we also have the @dry_rb Twitter handle and we have purchased dry-rb.org so will be renaming it soon, I will have a chat with the Gitter folks to see whether we can get everyone automagically moved to the new room (as I know that happened with the Lotus/Hanami change), judging from https://help.github.com/articles/renaming-an-organization/ it should be pretty low-impact for everyone (however, please feel free to raise any objections you may have)
Andy Holland
@AMHOL
Mar 14 2016 14:51
OK, we're renamed
Piotr Solnica
@solnic
Mar 14 2016 15:02
@AMHOL you know how to configure github pages with a custom domain?
Andy Holland
@AMHOL
Mar 14 2016 15:03
Nah, not done it before
Never used github pages TBH lol
Piotr Solnica
@solnic
Mar 14 2016 15:05
@AMHOL where did you get the domain?
it’s super simple when you’re using dnsimple
Andy Holland
@AMHOL
Mar 14 2016 15:05
1&1
Piotr Solnica
@solnic
Mar 14 2016 15:05
you need some special records
Fran Worley
@fran-worley
Mar 14 2016 15:07
You actually don't. DNSimples special records are just an easier way
@fran-worley ah ok :)
Andy Holland
@AMHOL
Mar 14 2016 15:07
TY
Fran Worley
@fran-worley
Mar 14 2016 15:10
Sorry the gitter app sends messages when you change to a different app hence my I helpful half message.
I was just looking up what the required records are but it looks like you guys have got it covered!
as you can see, we’ve got an official twitter account now, follow us! :)
Seba Gamboa
@sagmor
Mar 14 2016 15:43
@solnic another alternative is Cloudflare it’s free with HTTPs, CDN and CNAME support at root
Piotr Solnica
@solnic
Mar 14 2016 15:44
@sagmor thanks, github is good enough :) at least for now
Seba Gamboa
@sagmor
Mar 14 2016 15:44
I meant for DNS (Instead of DNS Simple)
Piotr Solnica
@solnic
Mar 14 2016 15:44
dooh :)
RKushnir
@RKushnir
Mar 14 2016 15:49

as you can see, we’ve got an official twitter account now, follow us! :)

nice! already had a couple of times when I wanted to tag dry in a tweet and couldn’t find it

Piotr Solnica
@solnic
Mar 14 2016 15:50
@RKushnir now you can :)
James Hamilton
@wjdhamilton
Mar 14 2016 16:25
@AMHOL @krisleech Hi guys! Just got round to opening my Gitter account, it was nice to meet you all on Friday
Andy Holland
@AMHOL
Mar 14 2016 16:30
Hi @wjdhamilton, you remembered Gitter :) Was nice to meet you too :)
Piotr Solnica
@solnic
Mar 14 2016 16:30
damn, I should’ve gone too :P
Andy Holland
@AMHOL
Mar 14 2016 16:31
Definitely should, there will be more xD
James Hamilton
@wjdhamilton
Mar 14 2016 16:31
@AMHOL thanks! How's your day going?
Andy Holland
@AMHOL
Mar 14 2016 16:31
It's all going good apart from DNS configuration with 1and1 :joy:
How about you?
Piotr Solnica
@solnic
Mar 14 2016 16:32
“the day was perfect, but then I registered a new domain"
James Hamilton
@wjdhamilton
Mar 14 2016 16:32
Not too bad, spent the morning struggling through some CSS for a client project and then pushed on with EasyJSONMatcher in the afternoon
Andy Holland
@AMHOL
Mar 14 2016 16:32
That's the gist of it
Oh, that's the project you were talking about, I'll check it out
James Hamilton
@wjdhamilton
Mar 14 2016 16:33
Feel free, it's not really at production yet but any feedback is appreciated!
Andy Holland
@AMHOL
Mar 14 2016 16:40
@wjdhamilton looks cool, definitely looks like something you could do with dry-validation too
Only had a quick look at the readme so far though
Piotr Solnica
@solnic
Mar 14 2016 16:42
yes, dry-validation is for JSON as well
I’ll be adding Dry::Validation.JSON too
pretty similar to Form wrt coercion
it’ll probably have the option to parse input string into JSON as a preprocessing step
should be useful
oh and dry-types will have json type category too
again, similar to form
James Hamilton
@wjdhamilton
Mar 14 2016 16:44
Thanks, I've been looking at dry-validation as well to see if I can lean on it to do the actual validating. The long term goal is to wrap the library so that it can handle use cases like JSONAPI or other stable meta-schemas (is that the right term?? :worried: ). I was also thinking of building a supporting website called break_easy_son_matcher so that people can register any schemas it doesn't validate properly. Possibly a little too adventurous for this stage but one can dream...
Piotr Solnica
@solnic
Mar 14 2016 16:45
yeah it’s possible already but lower-level APIs are not as polished as the DSL
so building a schema programmatically is going to be rough right now, I think
I’d be interested in improving this though
dry-validation is actually just a front-end to dry-logic + error message transformation
so what it’s doing is just giving an API for building dry-logic rules specific to validating data
James Hamilton
@wjdhamilton
Mar 14 2016 16:48
I'll have a closer look at them on Friday. Most of my validation logic is basically a begin/rescue from attempting type coercion using Ruby's core string parsers.
Piotr Solnica
@solnic
Mar 14 2016 16:48
that’s not a good idea, some coercion logic in Ruby is just not suitable
James Hamilton
@wjdhamilton
Mar 14 2016 16:49
Not really sure that's the right way to do it, but right now I figure that if it works I'll use it and then see if I can refine it later
Piotr Solnica
@solnic
Mar 14 2016 16:49
ie ''.to_i # 0
I separated various coercible type categories in dry-types because of this reason
James Hamilton
@wjdhamilton
Mar 14 2016 16:49
I see. That would definitely be a problem. Do you mind if I inspect your code?
and dry-validation uses dry-types for coercions
@wjdhamilton I don’t mind :)
it wouldn’t be on github otherwise :D
James Hamilton
@wjdhamilton
Mar 14 2016 16:52
I know, but I just wanted to be polite - they look broadly similar to what I'm trying to do except that you have covered the edge cases
:smile:
Piotr Solnica
@solnic
Mar 14 2016 16:52
sure :)
both libs were born after dealing with painful edge cases for years using other libs…:/
James Hamilton
@wjdhamilton
Mar 14 2016 16:54
I know...it seems weird to me that there isn't a high profile library out there that already does this
Piotr Solnica
@solnic
Mar 14 2016 16:54
exactly
I was so frustrated with this for years
people keep using what rails provides and continue with the struggle :(
I really hope dry stuff will provide solid and better alternatives
feels like we’re getting there :)
James Hamilton
@wjdhamilton
Mar 14 2016 16:56
It just seemed daft to me! :smile: I've been holding off on an API I've got to finish until I can get the validation side of things working. I think that your DSL looks really nice and very compact. It should satisfy a lot of use cases.
Piotr Solnica
@solnic
Mar 14 2016 16:56
thanks, it’s been crazy hard to get it done, I hope we won’t find too many bugs haha
James Hamilton
@wjdhamilton
Mar 14 2016 16:57
Yeah, I know the feeling! But then again a bug fixed is one less to worry about :smile:
Piotr Solnica
@solnic
Mar 14 2016 16:59
there are three things which made this so hard: 1) we have both macros + blocks working 2) nested data can be validated using nested schemas or not 3) dsl implementation in ruby == lots of mutable state
I’m undecided if 2 was worth the effort though, nested schemas are slower vs nested key definitions but the implications are huge wrt impl complexity on dry-v side
James Hamilton
@wjdhamilton
Mar 14 2016 17:01
I think it depends on how you intend people to use it. Personally, I don't think performance is as important as accuracy when testing.
Piotr Solnica
@solnic
Mar 14 2016 17:01
I want to keep it very fast, but I also prefer simpler code so I dunno, nested key definitions may go away for 1.0
btw I’m talking about this specifically:
key(:location) do
  hash? do
    key(:lat).required
    key(:lat).required
  end
end

# vs

key(:location).schema do
  key(:lat).required
  key(:lat).required  
end
both do the same, but the former is faster :)
James Hamilton
@wjdhamilton
Mar 14 2016 17:03
What is the difference in practise between the two?
Piotr Solnica
@solnic
Mar 14 2016 17:03
schema allows you do re-use exiting schemas so ie you could do schema(SomeSchema)
and internally it’s working differently as it’s using nested schemas
so more object allocations and a bit more work at runtime
I haven’t measured the perf difference though, gotta do it
James Hamilton
@wjdhamilton
Mar 14 2016 17:05
Ah, I see! Personally, I think that if you're testing an resourceful API you would want to be able to register the schemas so that you can reuse the representation of a record in index and show routes.
Piotr Solnica
@solnic
Mar 14 2016 17:05
yeah, re-using schema should be a common practice
James Hamilton
@wjdhamilton
Mar 14 2016 17:07
I recursively create a Node object for each Hash that is expected in the payload. A Node can then be registered with a central static library.
Basically, the idea is that you can insert any of these nodes into another node so that they can be reused anywhere else in the program
Piotr Solnica
@solnic
Mar 14 2016 17:11
sounds the same with schemas
James Hamilton
@wjdhamilton
Mar 14 2016 17:14
Let me know if you'd like me to run the performance tests for you, to give you another set of results from a different machine
Piotr Solnica
@solnic
Mar 14 2016 17:15
@wjdhamilton ah thanks :) so far I only have 3 benchmarks but I haven’t pushed them yet (too messy). I’ll clean them up and push soon to main repo
ok I gotta say I’m not super happy with dry-constructor vs dry-initializer - should we merge them or something?
the latter is definitely bigger in functionality scope
but I gotta say I would love to start using it in many places already, just not sure if it should maybe re-use APIs from dry-constructor or should we merge dry-constructor in or…??
@AMHOL @nepalez ^^
Michał Pietrus
@blelump
Mar 14 2016 17:17
@solnic , I'm getting lib/dry/types/constructor.rb:54:inmethod_missing': undefined method to_ast' for #<Dry::Types::Constructor:0x00000003a42538> (NoMethodError)` for such usage:
require 'bundler'
Bundler.require

module Types
  include Dry::Types.module
end

form = Dry::Validation.Form do
  PhoneNumber = Types::Form::Int

  key(:phone_number).required(PhoneNumber)
end

form.({})
Piotr Solnica
@solnic
Mar 14 2016 17:18
you need a constrained type, it’s the only reason why you may want to pass in a type object to key def
Michał Pietrus
@blelump
Mar 14 2016 17:18
uhm
let me check
Piotr Solnica
@solnic
Mar 14 2016 17:19
schema will build an input processor using form types so no need to do what you tried
types are for inferring validation rules, not coercions, this is a separate concern
gotta make that clear in the docs :)
Andy Holland
@AMHOL
Mar 14 2016 17:20
@solnic @nepalez I'd like dry-constructor to stay simple, I think dry-initializer should be usable on any method, rather than just the initializer, although I'm sure you already told me why that was a bad idea lol
Piotr Solnica
@solnic
Mar 14 2016 17:21
but naming…they sound like if they were doing the same
Michał Pietrus
@blelump
Mar 14 2016 17:21
@solnic , and how is a primitive form element related to Types::Form::xx ? All form elements are Types::Form::String ?
Piotr Solnica
@solnic
Mar 14 2016 17:22
@blelump all Types::Form::* are constructors with coercions specific to form, they expect string as input
Andy Holland
@AMHOL
Mar 14 2016 17:22
Yeah, I feel like dry-initializer is more about the parameter typing
We could call it dry-strong-parameters :joy:
Piotr Solnica
@solnic
Mar 14 2016 17:22
dry-bigger-constructor :D
lol :)
@blelump ie Types::Form::Int has primitive set to Integer and uses a constructor with coercion function set toDry::Types::Coercions::Form.to_int
what’s really nice about it is that it’s gonna turn empty strings to nils
Michał Pietrus
@blelump
Mar 14 2016 17:24
yup, I've already noticed that :-)
Piotr Solnica
@solnic
Mar 14 2016 17:24
and it’s not gonna bite you since you can say if something can be nil or not
so none? | int? and you’re done
or maybe(:int?) using a macro
it actually solves a pretty common problem :)
“oh, I want this to be nil when it’s empty” and then “oh oh but not in THIS case"
Piotr Solnica
@solnic
Mar 14 2016 17:30
this behavior deserves a good mention in docs I suppose
Michał Pietrus
@blelump
Mar 14 2016 17:31
yup
@solnic , but assume I've got {registered: "1"} and this comes to dry-v. May I use Types::Form::Bool or I need Types::Form::Bool.constrained(smth) ?
Types::Form::Bool['1'] returns true which is really cool, but how to use it with dry-v ?
Piotr Solnica
@solnic
Mar 14 2016 17:35
@blelump required(:bool?)
Michał Pietrus
@blelump
Mar 14 2016 17:35
uhm
Piotr Solnica
@solnic
Mar 14 2016 17:36
it’s gonna coerce it to true
types that you pass to key are not used for coercions
Michał Pietrus
@blelump
Mar 14 2016 17:36
tried to make it to complicated :worried:
too*
Piotr Solnica
@solnic
Mar 14 2016 17:36
coercions are inferred from type expectations
Michał Pietrus
@blelump
Mar 14 2016 17:52
@solnic , thanks !
Piotr Solnica
@solnic
Mar 14 2016 18:20
speaking about coercions, I realized yesterday we need number? predicate and a corresponding form coercion to_number
Tim Riley
@timriley
Mar 14 2016 22:56
@solnic How would I do this in the new, nicer API?
      key(:reviews) do |reviews|
        reviews.filled? & \
        reviews.each do |review|
          review.key(:summary) { |summary| summary.filled? }
          review.key(:rating) { |rating| rating.gteq?(1) & rating.lteq?(10) }
        end
      end
timriley @timriley is playing around with key(:reviews).each do … end atm
Piotr Solnica
@solnic
Mar 14 2016 23:11
Like that ^
each now prepends an array? check
Just like schema prepends hash? check
@timriley ^^
Tim Riley
@timriley
Mar 14 2016 23:13
Hi. Right now I have this:
    Dry::Validation.Form do
      key(:title).required
      key(:rating).required(:int?)

      key(:reviews).each do
        key(:summary).required
        key(:rating).required(:int?)
      end
    end
Which loads. And when I call it, I get these messages:
sch.({}).messages
=> {:reviews=>["is missing"], :rating=>["is missing"], :title=>["is missing"]}
Oh yeah, that looks right.
Piotr Solnica
@solnic
Mar 14 2016 23:14
Haha...
Tim Riley
@timriley
Mar 14 2016 23:15
Brain fart. Sorry!
OK, now this:
[6] pry(main)> sch.({reviews: [{}]}).messages
=> {:reviews=>{0=>{:summary=>["is missing"]}}, :rating=>["is missing"], :title=>["is missing"]}
Piotr Solnica
@solnic
Mar 14 2016 23:15
No worries. It's a learning curve
Tim Riley
@timriley
Mar 14 2016 23:15
I wonder why there’s no :rating error inside review 0?
p.s. that structure looks muchhhhh nicer in general
Piotr Solnica
@solnic
Mar 14 2016 23:16
Oh now that looks like a bug. Please report
Tim Riley
@timriley
Mar 14 2016 23:16
OK!
Piotr Solnica
@solnic
Mar 14 2016 23:16
I added this last-moment so super fresh code there
Thanks for testing btw :)
Tim Riley
@timriley
Mar 14 2016 23:19
No worries! I’ll have this baked into a formalist test shortly.
Piotr Solnica
@solnic
Mar 14 2016 23:21
Sweet. Glad you like new error structure
Tim Riley
@timriley
Mar 14 2016 23:36
Hmmm:
Dry::Validation.Form do
  key(:title).required
  key(:rating).required(:int?)

  key(:reviews).each do
    key(:summary).required
    key(:rating).required(:int?, qteq?: 1, lteq?: 10)
  end

  key(:meta) do
    hash? do
      key(:pages).required(:int?)
    end
  end
end
NoMethodError: undefined method `visit_p' for #<Dry::Types::Compiler:0x007fda74836200 @registry=Dry::Types>
Did you mean?  visit
It works if I change :meta to this:
key(:meta).schema do
  key(:pages).required(:int?)
end
Piotr Solnica
@solnic
Mar 14 2016 23:39
That's a bug in input handler compiler. Please report
Tim Riley
@timriley
Mar 14 2016 23:39
OK, I’ll do both now :)
Piotr Solnica
@solnic
Mar 14 2016 23:40
i should run schema specs against all types of schemas to improve coverage