diff options
author | pdp8 <pdp8@pdp8.info> | 2023-09-14 14:15:59 +0200 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2023-09-14 14:15:59 +0200 |
commit | 49de4bbdf6d68fef2133f1399131286decae3039 (patch) | |
tree | 3d232ca4447ffd9142801d1bd31e35fe6471be5b | |
parent | eea88e8022d3fd3c46401e1a297ebd7318c3c7b1 (diff) |
update_collection fixed
-rw-r--r-- | helpers.rb | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -106,13 +106,14 @@ helpers do collection = JSON.parse(json) objects.each do |object| id = object['id'] || object - if action == 'add' + if action == 'delete' collection['orderedItems'].delete_if { |o| o['id'] == id or o == id } - elsif action == 'delete' + elsif action == 'add' ids = collection['orderedItems'].collect { |i| i['id'] } collection['orderedItems'] << object unless ids.include?(id) or collection['orderedItems'].include?(id) end end + collection['orderedItems'].uniq! collection['totalItems'] = collection['orderedItems'].size f.rewind f.puts collection.to_json |