RedHatInsights/insights-host-inventory

Replace Host.to_json() methods with different exporter objects

dehort opened this issue · 1 comments

Think about replacing the to_json() methods (there are 2 now) with an object that exports the data in the correct format.

Thinking out loud here... Maybe this doesn't really need to be an object. Maybe a simple exporter function that gets passed around. Maybe its a class with the __call__() method on it.

The Host db object shouldn't be responsible for knowing all the different export formats.

Not only it’s not the DB object’s responsibility to export JSON or be built from JSON. I’d say that even the other methods like update, update_display_name etc. don’t belong there. They do the application logic and not anything related to the ORM.

Moreover the from_json, to_json and to_system_profile_json methods don’t even do anything related to JSON. They just (de)serialize the data to/from a dictionary. The fact that these dictionaries relate to JSON in other parts of the application is not relevant to the model.