solnic / virtus

[DISCONTINUED ] Attributes on Steroids for Plain Old Ruby Objects
MIT License
3.77k stars 229 forks source link

Allow fallback to default value when assigning nil #370

Open lime opened 7 years ago

lime commented 7 years ago

This is a revamp of the feature proposed in #292, though named differently. I tried to avoid confusion by making the name pretty explicit, but I'm open to suggestions if you feel there are better naming options.

When configuring use_default_on_nil: true, an attribute which gets set to nil will fallback to the :default value.

The implementation is heavily based on the :nullify_blank option in #314.

Let me know what you think. :)