These are chat archives for dry-rb/chat

23rd
Jan 2017
Piotr Solnica
@solnic
Jan 23 2017 08:22
@nepalez hey man, seems like dry-initializer 1.0.0 is much slower than 0.10. rom specs finish in ~2.2sec on 1.0 and ~1.5sec on 0.10 so that’s a huge difference
Piotr Solnica
@solnic
Jan 23 2017 17:45
Bundler could not find compatible versions for gem "concurrent-ruby":
  In snapshot (Gemfile.lock):
    concurrent-ruby (= 1.0.4) java
  In Gemfile:
    dry-logic java was resolved to 0.4.1, which depends on
      dry-core (~> 0.2) java was resolved to 0.2.3, which depends on
        concurrent-ruby (~> 1.0) java
    dry-logic java was resolved to 0.4.1, which depends on
      dry-core (~> 0.2) java was resolved to 0.2.3, which depends on
        concurrent-ruby (~> 1.0)
gaaah what gives Bundler?
Pierre-Alexandre Kofron
@kofronpi
Jan 23 2017 17:52
hello ! I'm kinda new to dry-rb, and I don't understand how to validate a condition on a array, specifically a any? condition
i'm trying to use high-level rules
Pierre-Alexandre Kofron
@kofronpi
Jan 23 2017 17:59
(in dry-validation)
Piotr Solnica
@solnic
Jan 23 2017 18:48
@kofronpi what exactly do you want to check?
Pierre-Alexandre Kofron
@kofronpi
Jan 23 2017 18:50
@solnic at least one value of the collection/array should have a given value
one member of the collection should have a given value *
Piotr Solnica
@solnic
Jan 23 2017 18:53
@kofronpi just use includes? ie required(:arr).value(:array?, includes?: VALUE)
Pierre-Alexandre Kofron
@kofronpi
Jan 23 2017 18:53
thanks :)
but it does not really work : what if i want to map my array before ?
for instance an array of hash parameters (collection from a form hash)
Piotr Solnica
@solnic
Jan 23 2017 18:56
@kofronpi wdym?
Pierre-Alexandre Kofron
@kofronpi
Jan 23 2017 18:56
and I need to map { |m| m[:some_value] }
Piotr Solnica
@solnic
Jan 23 2017 18:56
@kofronpi so it’s an array with hashes?
Pierre-Alexandre Kofron
@kofronpi
Jan 23 2017 18:56
yes
Piotr Solnica
@solnic
Jan 23 2017 18:57
and there must be a key with a specific value?
Pierre-Alexandre Kofron
@kofronpi
Jan 23 2017 18:57
all hashes have this particular key, at least one hash must have a specific value
Piotr Solnica
@solnic
Jan 23 2017 18:58
oh uhm, that’s an interesting use case
yeah so go for a custom validate block
Pierre-Alexandre Kofron
@kofronpi
Jan 23 2017 18:58
basically I'm looking for a way to map or map/reduce collections before validating them
Piotr Solnica
@solnic
Jan 23 2017 18:58
validate(must_include_foo: :arr) { |arr| arr.any? { |el| el[:foo] == VALUE } }
Pierre-Alexandre Kofron
@kofronpi
Jan 23 2017 18:58
when you don't necessarily control the shape of the incoming data
ha awesome, exactly what I was looking for ! thanks :)
Piotr Solnica
@solnic
Jan 23 2017 18:59
if you want to map/reduce it prior validation then you can simplify your schema validation according to the result of your mapping, up to you what makes more sense :)
ie if you don’t care about rest of hashes and their structure, then I’d recommend collapsing this array<hash> into <array<values> and use includes? predicate
Pierre-Alexandre Kofron
@kofronpi
Jan 23 2017 19:00
that's what I was going for in the first place, but I'm using Reform + dry-validation and didn't know how to do it
Pierre-Alexandre Kofron
@kofronpi
Jan 23 2017 19:14
anyway thank you :)
Piotr Solnica
@solnic
Jan 23 2017 22:41
got some news for you folks (important for rom/dry projects): https://www.icelab.com.au/notes/piotr-solnica-joins-icelab