These are chat archives for dry-rb/chat

14th
Jun 2018
Chris Richards
@cmrichards
Jun 14 2018 11:52
Is it possible to have an optional key with dry-struct?
Pavel Argentov
@argent-smith
Jun 14 2018 12:28
attribute :foo, Types::Bar.meta(omittable: true)
Chris Richards
@cmrichards
Jun 14 2018 12:32
Thanks
Pavel Argentov
@argent-smith
Jun 14 2018 12:32
or, in the struct class body:
transform_types { |t| t.meta(omittable: true) } -- this makes all attributes omittable
Chris Richards
@cmrichards
Jun 14 2018 12:34
Does setting omittable mean that the type won't be enforced for new objects?
Or should a default be set to avoid a type problem?
Nikita Shilnikov
@flash-gordon
Jun 14 2018 12:37
fwiw, it only makes sense to use omittable for optional types
but I think it's also possible not to have optional
also, you don't need omittable for default types, it's implied
Chris Richards
@cmrichards
Jun 14 2018 19:58
What's the best way to create json from dry-struct objects in rails? to_json works, but it doesn't let me pick additional methods on the structs to include in the json
Tim Riley
@timriley
Jun 14 2018 22:10
Some kind of serializer object is probably best, @cmrichards