These are chat archives for dry-rb/chat

23rd
Nov 2015
Hannes Nevalainen
@kwando
Nov 23 2015 08:19
@solnic, regarding dry-validations, the returned error set is "flat" even though the input can be nested. If I have two nested objects with the same attributes names (like two addresses) I cannot distinguish which one is not valid from the errors return from the validator
Hannes Nevalainen
@kwando
Nov 23 2015 09:04
@solnic never mind, I used it wrong
Hannes Nevalainen
@kwando
Nov 23 2015 09:39
how do I get an AST array from a Dry::Validation::Error::Set?
Piotr Solnica
@solnic
Nov 23 2015 09:59
to_ary
@kwando ^
Hannes Nevalainen
@kwando
Nov 23 2015 10:01
thanks, though it blows up in the compiler some visit_* seems to be missing
Piotr Solnica
@solnic
Nov 23 2015 10:01
Yeah it's not finished
Hannes Nevalainen
@kwando
Nov 23 2015 10:02
undefined method `visit_[:input, [:manager, nil, [:rule, [:manager, [:predicate, [:key?, [:manager]]]]]]]'
almost thought so =)
Piotr Solnica
@solnic
Nov 23 2015 10:02
I need to tweak things a bit first before I can finish error compiler
Hannes Nevalainen
@kwando
Nov 23 2015 10:03
just trying it out on a write-and-throw away import script =)
Piotr Solnica
@solnic
Nov 23 2015 10:03
Specifically change schema dsl to produce rule ast and then compile that ast into rules
This may cause some changes in the rule ast so I'm holding off with error compiler
Hannes Nevalainen
@kwando
Nov 23 2015 10:12
ah, ok. Like the DSL so far though, has the right "feel" to it =)
Hannes Nevalainen
@kwando
Nov 23 2015 18:57
@solnic T think nesting more than one level is broken in dry-validation
Piotr Solnica
@solnic
Nov 23 2015 19:01
@kwando nesting what?
Hannes Nevalainen
@kwando
Nov 23 2015 19:06
class Schema < Dry::Validation::Schema
  key(:name) { |n| n.filled? }
  key(:data) do |data|
    data.key(:invoice_address) do |invoice_address|
      %i[street zip city country].each do |f|
        invoice_address.key(f, &:filled?)
      end
    end
end

schema = Schema.new
schema.call({
                data: {
                    invoice_address: {}
                }
            })
vendor/bundle/bundler/gems/dry-validation-57d86bbfc390/lib/dry/validation/rule.rb:61:in `block in call': undefined method `call' for :street:Symbol (NoMethodError
Piotr Solnica
@solnic
Nov 23 2015 19:10
@kwando oh that should work, please report an issue
Hannes Nevalainen
@kwando
Nov 23 2015 19:14
@solnic done
Piotr Solnica
@solnic
Nov 23 2015 19:26
@kwando it’s weird though, in specs we have a more complicated example
there are 3 levels, works just fine
oh
you use each
blocks must return rules
use map instead of each, it’s gonna work
I may improve this though so it’s not required
although I wouldn’t recommend using each or map there
even if it means some duplication
it adds noise to the code w/o much benefit
Hannes Nevalainen
@kwando
Nov 23 2015 19:35
@solnic doh, unrolled those loops now and it works
fyi map didn't work
I was building the validator dynamically, hence it seemed like a good idea to use some meta programming
Piotr Solnica
@solnic
Nov 23 2015 19:37
yeah, for that I will have an ast for you later this week
using a dsl for building things up dynamically is not the way to go imo
Hannes Nevalainen
@kwando
Nov 23 2015 19:40
I think your right, just using whats there =)
Piotr Solnica
@solnic
Nov 23 2015 19:51
@kwando I’ll be refining rule ast and adding a rule compiler