davydovanton / shallow_attributes

Simple and lightweight Virtus analog.
MIT License
101 stars 18 forks source link

allow_nil option transforms nil values when should not #35

Open javierseixas opened 4 years ago

javierseixas commented 4 years ago

Hi!

With #27 and its release in v0.9.5 a bug was introduced: nil values are converted to 0, 0.0 or '' if allow_nil is not allowed.

I think that the behavior should be that a nil should be allowed if option is enabled, but if not, the value should remain.

So, in the Integer case, I would suggest:

case value
when nil then options[:allow_nil] ? nil : value
...
davydovanton commented 4 years ago

hey, sorry for the long delay. Thanks for the report!

I think it will be a good idea to fix it. Do you want to prepare PR?