As part of the feature to add causation_id to events emitted from reactors I found it's not so easy. We don't want to mutate events, instead we want an easy way to duplicate events while making the specified changes.
Changes
Added Event#to_h method. Pretty straight-forward: returns a hash of the event attributes.
Added Event#with method. This provides a way to create a new event identical to the old event except for the provided changes. Example:
Context
As part of the feature to add
causation_id
to events emitted from reactors I found it's not so easy. We don't want to mutate events, instead we want an easy way to duplicate events while making the specified changes.Changes
Added
Event#to_h
method. Pretty straight-forward: returns a hash of the event attributes.Added
Event#with
method. This provides a way to create a new event identical to the old event except for the provided changes. Example:Of course,
with
can accept any number of event attributes: