-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need a constructor type to omit optional attributes and support nil
for defaults
#32
Comments
Is this what you need?
What's the source of data for your entities?
We do not use
FactoryGirl, or any test-related use cases, this is not really relevant. Testing needs tools dedicated to testing. We have rom-factory which can build structs and we can add support for setting all attributes to
No, as I mentioned above, |
@solnic I just ran into this same issue, where some models have 'optional' attributes that are not set immediately on creation. It would be preferable to just have |
We'll address this, related issue is dry-rb/dry-types#194 |
This was addressed, see #64 |
I use
dry-struct
to build my domain entities and value objects.Some entities has a lot of optional fields, that I don't want to specify.
I can use
constructor_type :schema
, but it allows to 'forget' required key.I can use
strit_with_defaults
and.default(nil)
to all my optional fields, butTypes::Strict::String.optional.default(nil)
is too much as for me.Moreover,
strict_with_defaults
doesn't acceptnil
value for attributes with default value.I use default attributes defined in Entity because: a) they are often business rules b) it gives encapsulation. Application still may send
nil
value for that attribute, the most obvious example isFactoryGirl
who builds the object. And it's still desirable for Entity to set default value.Currently, no constructor type fits this needs.
P.S. Does it make sense to consider
.optional
attribute as one which has.default(nil)
?The text was updated successfully, but these errors were encountered: