These are chat archives for dry-rb/chat

22nd
Dec 2015
Hannes Nevalainen
@kwando
Dec 22 2015 07:33 UTC
@solnic how do you specify rules for keys at different nesting depths?
Piotr Solnica
@solnic
Dec 22 2015 09:24 UTC
@kwando possible but not supported by the dsl yet
Hannes Nevalainen
@kwando
Dec 22 2015 09:26 UTC
almost thought so, just checkin'. You are always a few steps ahead =)
Piotr Solnica
@solnic
Dec 22 2015 09:54 UTC
@kwando hah it's just that I am trying to cover all the use cases I had in my client app and it happens that it has this kind of validation :)
Hannes Nevalainen
@kwando
Dec 22 2015 09:55 UTC
I need to send a thank-you card to your client =P
Piotr Solnica
@solnic
Dec 22 2015 10:22 UTC
;) too bad I didn't manage to port rom validations to use dry-v
Piotr Solnica
@solnic
Dec 22 2015 11:56 UTC
@kwando it’s probably gonna work like that:
class UserSchema < Dry::Validation::Schema
  schema(:address) do |address|
    address.key(:city) { |v| v.filled? }
  end

  key(:group, &:filled?)

  rule(:some_address_rule) do
    rule(:group).filled? & schema(:address).rule(:city).filled?
  end
end
example makes no sense, probably, but shows the possible API
I also want to make it work for predicates that need values from different places in the input
ie rule(:foo, baz_bar_valid?: [schema(:stuff)[:baz], schema(:stuff)[:bar])
Piotr Solnica
@solnic
Dec 22 2015 12:01 UTC
this would call baz_bar_valid? with values from baz and bar keys under stuff parent
and as always, the really really cool aspect here is that it will not be called when these values are not in a valid state :)
…in terms of type-safety