These are chat archives for dry-rb/chat

9th
Mar 2016
Piotr Solnica
@solnic
Mar 09 2016 08:53
@AMHOL @timriley morning, seems like the website is in a good shape and now needs copy/content. I’m gonna create a branch and start adding stuff. I’d love to get some feedback, esp re copy :)
Tim Riley
@timriley
Mar 09 2016 09:57
I will keep watch on it!
Piotr Solnica
@solnic
Mar 09 2016 09:57
ideas/suggestions most welcome, as always
Andy Holland
@AMHOL
Mar 09 2016 12:30
Cool, I'll keep an eye out
Piotr Solnica
@solnic
Mar 09 2016 18:34
Anybody brave enough to test dry-v from current master? You can check out updated examples to see how it works now. Notice new DSL for defining schemas and ability to define nested schemas via key(:address).schema { .. }. Please try to play with this stuff a little bit, it would be very helpful :) I have a couple of tiny improvements to make and then it’s only a matter of updating docs and pushing a new release. /cc @kwando @fran-worley @blelump @AMHOL @timriley @apotonick @gotar
Michał Pietrus
@blelump
Mar 09 2016 18:39
@solnic , bomba! Perhaps tomorrow I'll try to put these changes into reform and see how it spins
Piotr Solnica
@solnic
Mar 09 2016 18:41
that would be awesome
Piotr Solnica
@solnic
Mar 09 2016 19:51
Dry::Validation.Schema do
  key(:tags).each(:str?)

  rule(red: [[:tags, 0]]) do |value|
    value.eql?('red')
  end
end
this now works too :joy:
Piotr Solnica
@solnic
Mar 09 2016 19:56
what’s really cool about this is that it will not crash if tags are not an array
Tim Riley
@timriley
Mar 09 2016 21:16
key(:my_key).schema do … end for nested keys makes a lot of sense
Piotr Solnica
@solnic
Mar 09 2016 21:26
@timriley you could rely on that in formalist to figure out when you have nested keys
Tim Riley
@timriley
Mar 09 2016 21:26
Let me take a look at the AST
Piotr Solnica
@solnic
Mar 09 2016 21:27
I believe you want to process schema's instance rules. It is a hash and if a value is another schema then you know what to do
Tim Riley
@timriley
Mar 09 2016 21:29
So just schema.rules?
These #inspect outputs are brutal ;)
So for examples/nested.rb, schema.rules[:address] is actually a Dry::Logic::Rule::Conjunction.
Piotr Solnica
@solnic
Mar 09 2016 21:33
@timriley it’s not for casual mortals ;)
ah right
sorry, I was being silly with that suggestion. you want to process Schema.rules of course
a nested schema is just a [:schema, schema_class] node
so you basically need a compiler for basic set of rules, and whenever it sees a schema node, it processes it recursively with itself
probably sth like visit_schema(klass); call(klass.rules); end
Tim Riley
@timriley
Mar 09 2016 21:42
right! I looked at schema.class.rule_ast before, and it did seem more familiar