_____ _ _ _ _ _ _ _ _ _ _ _ _ _ | __| ___ ___ |_| ___ | ||_| ___ ___ ___ | |_ | | ___ _ _ _ |_|| |_ | |_ ___ ___ |_|| | ___ ___ ___ ___ | | _ _ _ ___ ___ | | _| | _ _ ___ ___ |__ || -_|| _|| || .'|| || ||- _|| -_|| .'|| . || || -_| | | | || || _|| | | _|| .'|| || ||_ -| _ | _|| -_|| .'|| | | | | || . || _|| || . | | | ||_ -|| -_| _ |_____||___||_| |_||__,||_||_||___||___||__,||___||_||___| |_____||_||_| |_|_| |_| |__,||_||_||___|| | |_| |___||__,||_| |_____||___||_| |_||___| |___||___||___||_| |_|

I’ve been using the serialize extension from greg moreno for a few weeks now. But I’ve always been thrown of by the way the initialization of values is done.

Let’s say I create a User model with a :settings hash, containing :notify_mail => true as a default value. All the new created users are going to have the notify_mail value set. Now if I had another attr say :invites_count => 10. All users created afterwards are going to inherit from the two attributes, but what about all the previously created users ? They are still stuck with the only one attribute.

Since I didn’t want to have to refresh all the values for everyone every time I added another attribute to the :settings Hash, I modified the AttributeSerializer to make the setter return the default value if nothing is set.

Here is the gist :

Leave a Reply