-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing: Tagged Events! (journaled v4.1.0) (#22)
This adds a new `tagged: true` option to `journal_attributes`, and `Journaled.tagged`/`Journaled.tag!` helpers that allow events to be tagged with contextual metadata (useful for audit logs and tracing): ```ruby class MyEvent include Journaled::Event journal_attributes :attr_1, :attr_2, tagged: true end Journaled.tagged(foo: 'bar') do # events emitted in this scope will have a `tags` attribute with contents `{ "foo": "bar" }` end # events emitted in this scope will have a `tags` attribute with contents `{}` ``` All "tagged" events will be given a `tags` attribute, but it can be empty. Consuming apps with strict schema enforcement (`"additionalProperties": false`) will need to include the "tags" field in any relevant event schemas. Under the hood, this removes `RequestStore` in favor of `ActiveSupport::CurrentAttributes`. This is the new convention for Rails apps (available in 5.2+), so in theory consuming apps shouldn't be impacted by this, but out of caution we have incremented the gem a minor version (to 4.1.0).
- Loading branch information
Showing
14 changed files
with
291 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"type": "object", | ||
"title": "tagged_event", | ||
"additionalProperties": true, | ||
"required": [ | ||
"tags" | ||
], | ||
"properties": { | ||
"tags": { | ||
"type": "object", | ||
"additionalProperties": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Journaled | ||
class Current < ActiveSupport::CurrentAttributes | ||
attribute :tags | ||
attribute :journaled_actor_proc | ||
|
||
def tags=(value) | ||
super(value.freeze) | ||
end | ||
|
||
def tags | ||
attributes[:tags] ||= {}.freeze | ||
end | ||
|
||
def actor | ||
journaled_actor_proc&.call | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Journaled | ||
VERSION = "4.0.0".freeze | ||
VERSION = "4.1.0".freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.