These are chat archives for dry-rb/chat

15th
Mar 2017
Pablo Herrero
@pabloh
Mar 15 2017 02:03
Is there an easy way to customize how dates and date_time attributes ares parsed from strings by the forms?
Nikita Shilnikov
@flash-gordon
Mar 15 2017 07:39
@pabloh you can build a custom type for that. Time.constructor { ... }
Pablo Herrero
@pabloh
Mar 15 2017 08:32
@flash-gordon, and then you can just use it like this?:
CustomType = Time.constructor { ... }

Dry::Validation.Form do
  required(:date).filled(type?: CustomType)
end
Nikita Shilnikov
@flash-gordon
Mar 15 2017 08:42
@pabloh I'm not sure if type? will work, there are some issues with using custom types IIRC
    to_time = -> x { Time.iso8601("#{x}Z") }
    ISOTime = Types::Strict::Time.constructor(to_time)

    Schema = Dry::Validation.JSON do
      optional(:sent_at, :time).value(ISOTime)
...
that's what I have^
Pablo Herrero
@pabloh
Mar 15 2017 08:44
@flash-gordon , why do you need the second argument at optional?
can you not just do optional(:sent_at) { time? | value(ISOTime) }?
Nikita Shilnikov
@flash-gordon
Mar 15 2017 08:51
@pabloh the second argument is for type_specs, i.e. specifies value type, as far as I know dry-v atm can work without it, but slower
just test^ I dunno, not an expert here lol
Pablo Herrero
@pabloh
Mar 15 2017 08:53
hehe, I was trying... Dry::Types::Strict::Time did not work for some reason...
Nikita Shilnikov
@flash-gordon
Mar 15 2017 08:59
@pabloh mb related dry-rb/dry-validation#223
Pablo Herrero
@pabloh
Mar 15 2017 09:58
mmm...
Joakim Reinert
@jreinert
Mar 15 2017 12:38
hi, just want to point out that the link to hanami is broken
on the dry-types page
it links to https://hanamirb.org
which uses github's cert
you can only use http
Nikita Shilnikov
@flash-gordon
Mar 15 2017 12:46
@jreinert thx, fixed
Joakim Reinert
@jreinert
Mar 15 2017 12:51
@flash-gordon nice! That was quick!
Loïc Guitaut
@Flink
Mar 15 2017 14:51
Hey there! Do you know if it’s possible to raise (or report) errors on unknown parameters with dry-validation?
I didn’t see how to do this in the documentation
Loïc Guitaut
@Flink
Mar 15 2017 15:22
nvm found a way to do something similar with another approach