Module: Grably::Digest
- Defined in:
- lib/grably/core/digest.rb
Overview
Set of utilities to digest products and stat product set changes
Defined Under Namespace
Classes: ProductDigest
Class Method Summary collapse
- .build_diff(new_map, old_map) ⇒ Object
-
.diff_digests(old_products, new_products) ⇒ deleted, ...
Given two lists of product digests find missing, changed, and added products.
-
.differ?(old_products, new_products) ⇒ Boolean
Tells if two product digest lists are differ.
- .digest(*products) ⇒ Object
Class Method Details
.build_diff(new_map, old_map) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/grably/core/digest.rb', line 73 def build_diff(new_map, old_map) old_keys = old_map.keys.to_set new_keys = new_map.keys.to_set missing = old_keys - new_keys added = new_keys - old_keys updated = (old_keys & new_keys).reject do |product| old_map[product] == new_map[product] end [missing, added, updated] end |
.diff_digests(old_products, new_products) ⇒ deleted, ...
Given two lists of product digests find missing, changed, and added products
63 64 65 66 67 68 69 70 71 |
# File 'lib/grably/core/digest.rb', line 63 def diff_digests(old_products, new_products) # create maps of product sets old_map, new_map = [old_products, new_products].map do |products| return [] unless products Hash[*products.flat_map { |d| [d.product, d] }] end build_diff(new_map, old_map) end |
.differ?(old_products, new_products) ⇒ Boolean
Tells if two product digest lists are differ
88 89 90 |
# File 'lib/grably/core/digest.rb', line 88 def differ?(old_products, new_products) !diff_digests(old_products, new_products).flatten.empty? end |
.digest(*products) ⇒ Object
56 57 58 |
# File 'lib/grably/core/digest.rb', line 56 def digest(*products) products.map { |product| ProductDigest.of_product(product) } end |