Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Tim Riley
@timriley
@solnic you up for some feedback on dryrb/dry-validation#70 or are you still working through it?
Piotr Solnica
@solnic
@timriley it is a wip but shoot :)
Tim Riley
@timriley
I thought it might be. Was just going to say that the configure do configure do dance felt a bit funny :)
Piotr Solnica
@solnic
Yeah man it is not final
Tim Riley
@timriley
Right :)
Piotr Solnica
@solnic
Just wanted to maintain green build
Tim Riley
@timriley
heh, of course!
Piotr Solnica
@solnic
@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
I will keep watch on it!
Piotr Solnica
@solnic
ideas/suggestions most welcome, as always
Andy Holland
@AMHOL
Cool, I'll keep an eye out
Piotr Solnica
@solnic
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
@solnic , bomba! Perhaps tomorrow I'll try to put these changes into reform and see how it spins
Piotr Solnica
@solnic
that would be awesome
Piotr Solnica
@solnic
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
what’s really cool about this is that it will not crash if tags are not an array
Tim Riley
@timriley
key(:my_key).schema do … end for nested keys makes a lot of sense
Piotr Solnica
@solnic
@timriley you could rely on that in formalist to figure out when you have nested keys
Tim Riley
@timriley
Let me take a look at the AST
Piotr Solnica
@solnic
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
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
@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
right! I looked at schema.class.rule_ast before, and it did seem more familiar
Hannes Nevalainen
@kwando
@solnic cannot get your basic example to work https://gist.github.com/kwando/d8ad54d98acc0c6ca7c7
I've not spent a ton of time at this so I might just have missed something obvious
Piotr Solnica
@solnic
@kwando you need dry types and logic from master too
Sorry I forgot to mention that
Hannes Nevalainen
@kwando
ah, I missed dry-logic in my Gemfile
thx for the hint
this reads a little funny optional(:name).required =P
though it appears to do the same as optional(:name, &filled?)
Piotr Solnica
@solnic
It doesn't when you know how it works
Hannes Nevalainen
@kwando
>.< I know
Piotr Solnica
@solnic
Left side == key expectation
Right side == value expectation
Hannes Nevalainen
@kwando
How would I express this key(:name){|n| n.none? | (n.filled? & n.size?(2..50)) }
Michał Pietrus
@blelump
@kwando , I think smth like key(:name).maybe(size?: (2..50)), but dont trust me, I'm still learning it
Hannes Nevalainen
@kwando
@solnic key(:name).required(size?: 2..25) blows up
/Users/kwando/projects/dry-v-playground/vendor/bundle/bundler/gems/dry-logic-2b89feb6e426/lib/dry/logic/predicate.rb:26:in `curry': wrong argument type FalseClass (expected Proc) (TypeError)
Piotr Solnica
@solnic
@kwando ah that’s a known issue, we splat args so ranges and arrays get messed up, I’m gonna finally fix it
for now you can continue with the block-based approach
maybe means ‘a value can be nil or sth else'