aetherknight / recursive-open-struct

OpenStruct subclass that returns nested hash attributes as RecursiveOpenStructs
Other
286 stars 54 forks source link

Fix recursive update of parent node tables #22

Closed fervic closed 9 years ago

fervic commented 9 years ago

Fixes #9 by keeping a reference of the hash upon initialization instead of creating an empty hash. Only does this if specified in the options hash.

aetherknight commented 9 years ago

The implementation looks clean and straightforward. Once you make the changes to the tests, I'd be happy to merge it in.

fervic commented 9 years ago

@aetherknight I'm glad you suggested to add the test about not modifying the original hash because it is not passing. At the first level it is a different reference, but after that they continue pointing to the same structure. I don't know if the only option would be to store the references on a separate variable that is recursively passed to the initialize method.

fervic commented 9 years ago

I think I found a solution by deep duplicating the first input hash (when the flag is set to false).

I just tried using active_support's deep_dup just to be able verify it quickly. I will now work in bringing this logic into the class and then push so you can review.

fervic commented 9 years ago

@aetherknight it should be good to go now. Please review and let me know. At the end it wasn't as simple as I initially thought.

aetherknight commented 9 years ago

I'm going to merge this in, and then I'll address the recurse_over_arrays x deep_dup case before cutting a new release. Thanks for your hard work!