DmitryTsepelev / store_model

Work with JSON-backed attributes as ActiveRecord-ish models
MIT License
1.04k stars 85 forks source link

Improve `inspect` readability #162

Closed neilvcarvalho closed 9 months ago

neilvcarvalho commented 9 months ago

While debugging code backed by StoreModel, I had issues understanding some model attributes, as those that were more complex objects just printed the attribute's class and its memory address.

I saw something like:

=> #<Content::Text type: text, text: #<Content::Text::Base:0x000000011a9716f0>>

By contrast, the default Ruby inspect implementation calls inspect on all the object's instance variables:

=> #<OuterClass:0x0000000104ac87f8 @attribute=#<InnerClass:0x000000010466cf60 @text="string">>

Also, the strings are not quoted, making strings like "nil" and "false" show up as nil and false, which may lead to confusion.

This commit changes the inspect implementation to call inspect on the model attributes, fixing the issues stated above.