These are chat archives for dry-rb/chat

17th
Jun 2016
Jake Sower
@jakesower
Jun 17 2016 00:00
yeah. maybe each is the way to go.
Joe Van Dyk
@joevandyk
Jun 17 2016 00:00
but i don’t know how to get to match either a hash or a string there
Jake Sower
@jakesower
Jun 17 2016 00:00
does that match [{option_id: 1}]?
Joe Van Dyk
@joevandyk
Jun 17 2016 00:00
yes
Jake Sower
@jakesower
Jun 17 2016 00:02
hmmm. that's tricky. :)
maybe something along the lines of hash?.then{ required(:option_id).filled(:int?) } | str?
that being nested directly within the each block.
Joe Van Dyk
@joevandyk
Jun 17 2016 00:11
hm, got some 0 for 1 argument errors
Jake Sower
@jakesower
Jun 17 2016 00:19
I've had similar stuff. that's why I was working on the is_hash? alternative to hash? -- the former gives strange error. (though it's a known issue)
Joe Van Dyk
@joevandyk
Jun 17 2016 00:40
Still no luck. Feels like this should be possible, just don't know syntax
Jake Sower
@jakesower
Jun 17 2016 00:44
I'm drowning as well.
Jake Sower
@jakesower
Jun 17 2016 00:53
I'm playing around with your issue to take a break from mine. here's what I see
JoeSchema = Dry::Validation.Schema do
  each do
    str? | int?
  end
end

JoeSchema.([3, 'birdseed'])
that totally works
it's when I bring hashes into play that it starts with the strange errors
even works with arrays.
Joe Van Dyk
@joevandyk
Jun 17 2016 00:57
Ah, interesting
Jake Sower
@jakesower
Jun 17 2016 01:04
I think I solved it!
JoeSchema = Dry::Validation.Schema do
  configure do
    def iz_hash?(value)
      value.is_a?(Hash)
    end
  end

  each do
    str? | iz_hash?.then(schema{key(:option_id) { int? }})
  end
end
it's hacky, but shows that the issue is with hash?
JoeSchema.(['birdseed', {option_id: 3}]) will pass that
This message was deleted
Joe Van Dyk
@joevandyk
Jun 17 2016 01:24
Woah, thanks!
Joe Van Dyk
@joevandyk
Jun 17 2016 06:53
@jakesower i think this seemed to work, at least on master:
  each do
    str? | schema { required(:option_id).filled(:int?) }
  end
the error message isn’t the best though
says it must be a hash instead of being a string or a hash
Piotr Solnica
@solnic
Jun 17 2016 08:24
yeah we don’t support ORing messages YET :P
I’ve postponed this feature until we have a simplified error compiler
@joevandyk feel free to report an issue about ORing messages (it’s gonna be pretty awesome btw :D)
Nikita Shilnikov
@flash-gordon
Jun 17 2016 12:16
:heart:
Piotr Solnica
@solnic
Jun 17 2016 12:16
yeah so this is a really really huge improvement
@flash-gordon how did you measure mem consumption the other day?
Tim Riley
@timriley
Jun 17 2016 12:18
Boom!
Piotr Solnica
@solnic
Jun 17 2016 12:18
yes, boom :)
Nikita Shilnikov
@flash-gordon
Jun 17 2016 12:18
@solnic I think I used ps or sutin
Piotr Solnica
@solnic
Jun 17 2016 12:18
w/o input processors we definitely allocate way less objects
I wonder how to deprecate that now, it’s a bit tricky, I guess a warning when there’s required or optional w/o a type spec should be enough
Nikita Shilnikov
@flash-gordon
Jun 17 2016 12:31
@solnic now 32116 KB against 41052 KB and allocated objects 598617 vs 7094131
but the benchmark speaks for itself
Piotr Solnica
@solnic
Jun 17 2016 12:38
wait, so it’s 6495514 less object allocations? :laughing:
Nikita Shilnikov
@flash-gordon
Jun 17 2016 12:43
oops, I messed with numbers 732762 vs 7094131
no difference though
uhm, I mean 7094131 for old form and 732762 for new one
I'm just trying to do several things at once, I'm really bad in this :)