These are chat archives for dry-rb/chat

7th
Oct 2017
Andrew Kozin
@nepalez
Oct 07 2017 06:08

@untitaker dry-initializer follows a logics slightly different from dry-types.

Dry types describes an attribute -- what values you can assign to it. Here "optional" means that you can send nil.

Dry-initializer describes dependencies where "optional" means that you can send nothing here. Here nothing does not mean nil, nil is explicit value in ruby -- you can ignore an attribute at all.

This makes sense when you need to treat cases "(re)set some value to nil" differently from "do not change (skip) an attribute". (Think of request params, for example).

The difference cannot be expressed in a type of some value, because in the second case there is no value to assign a type. Instead, you have to express it as a property of the initialized instance -- that's why 'optional: true' is needed.

So yes, you need both, here is no duplication.