Maintaining a little stock-sync script for a fabric shop. It reads events and keeps running totals per SKU. The shop only cares about its own region, us-east, which comes from config/shop.yml. So in the restock branch I put the region in the hash pattern, figuring it would only match our events:
def handle(event)
region = @region
@log.debug("handling #{event[:type]} for #{region}")
case event
in { type: "restock", region: region, sku:, qty: }
@totals[sku] += qty
@log.info("restock #{sku} +#{qty} (#{region})")
in { type: "sale", sku:, qty: }
...
And @region is built in main.rb with config["region"].strip.
But the log has restock bolt-cotton-12 +40 (eu-west) and the total for that SKU is too high. The 40 got counted. The log line printing the region from the event seemed odd to me, but I didn't think much of it at first.
My first guess was the YAML string being different from the event string. Frozen, encoding, a trailing newline, something like that. I printed both with inspect and the us-east ones look identical. Added .strip, no change. It's running under rbenv on 3.1.4, not the old system ruby, which chokes on in.
So is this a YAML thing or is it how hash patterns work? I don't see how eu-west gets in at all...