These are chat archives for dry-rb/chat

Nov 2016
Maciej Mensfeld
Nov 14 2016 08:11
@solnic <3
Sergey Kukunin
Nov 14 2016 14:02
I try to reduce code duplication of writing schemas for my entities (they are pretty the same). Is there a way create validation schema based on entity automatically? Is it good idea?
How do you threat such duplication?
In my application, I need to accept and save about 40 different attributes. It turns out in a bunch of entities for that 40 attributes, and the same amount of schema validators
Lucas Hosseini
Nov 14 2016 14:03
@Kukunin Having both dynamically bound is probably a bad idea as your validations define an interface contract
Could you post an example?
Sergey Kukunin
Nov 14 2016 14:07
@beauby I think so as well. It's probably should be not automatic generator, but some set of helpers. Currently I have a lot of this:
      CoerciblePurpose =
        Types::Strict::Symbol.constrained(included_in: Domain::Mortgage::Loan::PURPOSES)
                             .constructor do |value|
          next value unless
because my entity is
      class Loan < Dry::Struct
        PURPOSES = [:purchase, :refinance, :construction].freeze
        Purpose = Types::Strict::Symbol.constrained(included_in: PURPOSES)
        attribute :purpose, Purpose
at least, we can reuse Loan::Purpose type
Lucas Hosseini
Nov 14 2016 14:08
Yeah that’s what I was gonna say