A small service builds a summary from passed objects and returns it as a plain Hash. Right now the behavior at the boundaries of copying and reading data is unstable: part of the result later changes together with the original objects, and some calls receive not the same set of data that was passed in.
InventoryReport.build(items, defaults: {}) must accept an array of objects and a hash of settings.id, name, meta, and tags.meta, use values from defaults, but do not modify the original defaults.tags in the result must be independent of the input arrays.InventoryReport.snapshot(report) must return a snapshot that can be read and modified separately from the original report.meta hash and a shared tags array.InventoryReport.build with these items and common default values.meta or tags after the call.InventoryReport.snapshot and modify it.defaults remained unchanged.items = [
{ id: 1, name: "Box", meta: shared_meta, tags: shared_tags },
{ id: 2, name: "Bag" }
]
build must not change after later edits to the input objects.snapshot must be a separate copy, not a window into the original report.defaults after the call must remain unchanged.ruby without additional frameworksUse line comments to explain the problem, its impact, the fix and how to test it.