davydovanton / shallow_attributes

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

allow_nil for strings and inverse logic of allow_nil #27

Closed morr closed 5 years ago

morr commented 5 years ago
  1. I added allow_nil option to String type so it works similar to numeric types. Because there is no reason why you should forbid nil values in string fields.

  2. Inverted logic of allow_nil because when you have such class

    class A
    include ShallowAttributes
    attribute :a, Integer, allow_nil: true
    end

and you initializing a with nil

A.new(a: nil)

you expect it's value to be nil, cause you specifically wrote allow_nil: true in class definition. But currently it has 0 value.

pry(main)> A.new(a: nil).a
0
coveralls commented 5 years ago

Coverage Status

Coverage increased (+0.0007%) to 99.879% when pulling 2885c3ab6ca1063b9aabea7942f912b981608206 on morr:nil-strings into 37fe19415397c78fcc40c562ea6b0b0b7c47cb16 on davydovanton:master.