These are chat archives for dry-rb/chat

31st
Oct 2017
Jeff Dickey
@jdickey
Oct 31 2017 05:04
@timriley sounds great. No problem making do for now; just wanted to raise awareness of (particularly) that app-name-generated-as-dot problem. Should I open an issue re that on dry-web-roda?
Tim Riley
@timriley
Oct 31 2017 07:56
Sure :)
Vsevolod
@stefkin
Oct 31 2017 09:28

Hi guys. I have an issue with dry-validation. I have a schema with a bunch of optional fields (23 to be exact). I need to check if at least on of the fields is filled.
I figured I could use a custom validation block. Something like:

  validate(has_some_value: DECIMAL_FIELDS) do |*fields|
    fields.any? { |field| !field.nil? }
  end

But I ended up with the following error:
ArgumentError: wrong number of arguments (23 for -1)

It pops up in dry-logic's curry rule which makes sense. Is there any way around this?

Vsevolod
@stefkin
Oct 31 2017 10:15

ok guys I ended up with the following rule:

  rule(any_value_filled: DECIMAL_FIELDS) do |*fields|
    fields.reduce(fields.first.filled?) { |acc, f| acc | f.filled? }
  end

somehow it doesn't produce the error. My only concern is that rule compiler repeats error message 23 times :)

Odin Dutton
@twe4ked
Oct 31 2017 23:23
I tried to post this on Discourse but I'm not sure if it failed or it's still in the moderation queue. Anyway, I'm having some trouble trying to ensure an array is filled with hashes and also checking the schema of those hashes.
require 'dry-validation'

schema = Dry::Validation.Schema do
  required(:foo).filled(:array?).each do
    schema do
      required(:bar).filled(:str?)
    end
  end
end

p schema.({}).errors
# => {:foo=>["is missing"]}

p schema.(foo: []).errors
# => {:foo=>["must be filled"]}

p schema.(foo: [1]).errors
# => {}

p schema.(foo: [{}]).errors
# => {}

p schema.(foo: [{bar: 'baz'}]).errors
# => {}
Is this supported?
Oops, I forgot to say “Hello” :wave: