New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of #to_h and #to_hash across our object models #7699

Open
lamont-granquist opened this Issue Sep 27, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@lamont-granquist
Contributor

lamont-granquist commented Sep 27, 2018

Most objects that aren't really hash like shouldn't implement #to_hash at all.

Objects like DataBagItem which really are a wrapper around a Hash (which does delegate all its methods to Hash) should implement #to_hash but should return the actual inner @raw_data hash. Returning the serialized version of the data bag with the json_class, etc is incorrect. I think we should likely implement a #for_json that returns the serialized hash version which #to_json should call consistently. Then many not-actually-hash-like objects would drop #to_hash entirely, they would have a #to_h which was aliased to #for_json. Other actually-hash-like objects would have #to_hash and #to_h that would be aliased together, while #for_json was the serialized version.

See #7697 and #7691

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment