These are chat archives for dry-rb/chat

28th
Sep 2016
Piotr Solnica
@solnic
Sep 28 2016 01:04
@Kukunin it’s not supported yet. I’ll make it work before 1.0.0 though, but there will be a limitation - if you use a type with constraints in a type spec, then this is the only way you will set your rules, so ie required(:phone, UsaPhone) will work (including rule inference from the type) but required(:phone, UsaPhone).maybe(:str?) will raise an arg error. So this means you either use types for everything or you define rules manually
Joe Van Dyk
@joevandyk
Sep 28 2016 01:21

I have input like:

variants: { Color: "Red", Size: "Large", Material: "" }

It's valid to use any string (for now, anyways) for the variant keys, but each variant needs to be filled in with a value. In this case, Material being blank is an error. How can I do that with dry-v? (again, the names of the keys can be whatever the user wants)

Tim Riley
@timriley
Sep 28 2016 01:26
You’d probably want to use the input macro
Joe Van Dyk
@joevandyk
Sep 28 2016 01:27
I can't figure out how to use that for this case
Piotr Solnica
@solnic
Sep 28 2016 01:29
that’s a feature planned for 1.0.0
Joe Van Dyk
@joevandyk
Sep 28 2016 01:30
ah ok
Tim Riley
@timriley
Sep 28 2016 01:30
It should already work for some things, as that spec suggests, though IIRC I found an issue with it when I tried to use it once
Joe Van Dyk
@joevandyk
Sep 28 2016 01:31
that validates keys right? not values?
Tim Riley
@timriley
Sep 28 2016 01:31
It validates the whole input object
Unrelated, I just put something together to let me “filter” a dry-container so it responds only to keys in a particular namespace:
module Main
  class NamespaceFilteredContainer
    attr_reader :container
    attr_reader :namespace

    def initialize(container, namespace)
      @container = container
      @namespace = namespace
    end

    def resolve(key)
      container["#{namespace}.#{key}"]
    end

    alias_method :[], :resolve
  end
end
created here:
require "formalist"
require "main/namespace_filtered_container"

Main::Container.namespace "main.formalist" do |container|
  container.finalize :formalist do
    container.register "embedded_form_renderers" do
      Main::NamespaceFilteredContainer.new(container, "main.formalist.embedded_form_renderers")
    end
  end
end
so I basically have a container that works to expose a sub-set of the keys in my main app’s container, which already has the auto-registration etc. setup that I want
I wonder if that would be a useful behaviour to put in dry-container itself?
Joe Van Dyk
@joevandyk
Sep 28 2016 01:50
@solnic any rough idea on how far out 1.0 is?
Piotr Solnica
@solnic
Sep 28 2016 01:51
@joevandyk later this year :)
Joe Van Dyk
@joevandyk
Sep 28 2016 01:51
Lol k
Piotr Solnica
@solnic
Sep 28 2016 01:51
depends on testing, the hardest part is done
it should also go hand-in-hand with 1.0.0’s of dry-types and dry-logic
Andy Holland
@AMHOL
Sep 28 2016 09:48
@timriley yeah could add something like that to dry-container, should probably define resolve rather than [] as [] just calls resolve
@timriley worth considering that other methods like register, merge, namespace etc. would need to be implemented to respect the scope too
Tim Riley
@timriley
Sep 28 2016 10:27
@AMHOL yeah, true. Anyway, not super urgent, I’ll file an issue and we can work through some stuff there too :) Also, hi! :wave:
Andy Holland
@AMHOL
Sep 28 2016 10:31
Hi :)
Did you ever take a look at dry-rb/dry-configurable#16 BTW?
Aleksandar Radunović
@aradunovic
Sep 28 2016 10:39

is there anyone else who encountered the issue of autoloading dry-rb validations in rails?

# lib/validations/something/form.rb

module Validations
  module Something
    Form = Dry::Validation.Form do
    end
  end
end

I added the path to config.autoload_paths, but constantly getting Unable to autoload constant Form, expected {FILE_PATH} to define it

Sergey Kukunin
@Kukunin
Sep 28 2016 10:56
@aradunovic are you trying to use Validations::Something::Form?
Tim Riley
@timriley
Sep 28 2016 11:42
@AMHOL I’ll give it a thorough looking at tomorrow, thanks for the reminder!
Andy Holland
@AMHOL
Sep 28 2016 11:42
Cheers :)
Aleksandar Radunović
@aradunovic
Sep 28 2016 12:32
@Kukunin yes
Sergey Kukunin
@Kukunin
Sep 28 2016 13:52
@aradunovic thus that's not related to dry-validation at all. Replace Dry::Validation.Form with some constant and you'll get the same error
Aleksandar Radunović
@aradunovic
Sep 28 2016 14:05
@Kukunin thank you. I knew it wasn't a dry-validation issue, but either Rails autoload or my messed config. Fixed it.
Piotr Solnica
@solnic
Sep 28 2016 19:09
Remove validation schemas from autoload paths