eventsimple 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b24c718c0873c73f051bf040aba71527ca20f08237e6bf97c20f308ac654404f
4
- data.tar.gz: 984f31379e00b61fee3afdcffa839386638840cbdca0f327d518ea6ee59ad4a5
3
+ metadata.gz: 394c4820e133907b2e63fe826b7891ab2cd0fbc1f436683b667ac9cfee73e57a
4
+ data.tar.gz: 70508717fa8b8a1b2528a38044648c3748b63ffd721c606ec66fdf959e54b53a
5
5
  SHA512:
6
- metadata.gz: 02eaddfd2440ef2df26d7029e7b4e4dddda0be6797b0a4e8df0184935644e745fa807a25d12f10927a395b14a0c016b4325a590be62997d2c82a7752d72aee4a
7
- data.tar.gz: 1818f9a233b7607248713c7e0d694cfd69342103ff9f394230908064ac756efd9be25a13683c1db46e2793f47f4b3b93343bf17fed8d63824e6331511edb131b
6
+ metadata.gz: 1150de14bcfc4580f7b2be46a406d602a29bcecb7b75aabd136215e8893fc8b4cc98fbfc29082cc1a7ac30cb7235e7ac81206e05532cdf260c74d8e68bf10176
7
+ data.tar.gz: 4d47af195c91593c5424c0f9a5316cd35e3c4aa9b135cbdb894fa86bcef72d899b1e6f1187afe063c627dbeb787d9bb0dfc310fc8de60ad0bbbf7d48cbbf4a60
data/CHANGELOG.md CHANGED
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## 2.3.0 - 2026-02-24
10
+ ### Added
11
+ - Per-event metadata class: pass `metadata_class:` to `drives_events_for` to use a custom metadata class for that event (Class or String).
12
+
13
+ ### Removed
14
+ - Global `metadata_klass` configuration. Set metadata class per event via `drives_events_for(..., metadata_class: MyMetadata)` instead. Default remains `Eventsimple::Metadata` when omitted.
15
+
9
16
  ## 2.2.1 - 2026-02-03
10
17
  ### Removed
11
18
  - Removed `DateTime` type support. Use `Time` type instead. DateTime objects are no longer supported.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eventsimple (2.2.1)
4
+ eventsimple (2.3.0)
5
5
  concurrent-ruby (>= 1.2.3)
6
6
  dry-struct (>= 1.8.0)
7
7
  dry-types (>= 1.7.0)
@@ -458,7 +458,7 @@ CHECKSUMS
458
458
  dry-types (1.9.0) sha256=7b656fe0a78d2432500ae1f29fefd6762f5a032ca7000e4f36bc111453d45d4d
459
459
  erb (6.0.1) sha256=28ecdd99c5472aebd5674d6061e3c6b0a45c049578b071e5a52c2a7f13c197e5
460
460
  erubi (1.13.1) sha256=a082103b0885dbc5ecf1172fede897f9ebdb745a4b97a5e8dc63953db1ee4ad9
461
- eventsimple (2.2.1)
461
+ eventsimple (2.3.0)
462
462
  factory_bot (6.5.6) sha256=12beb373214dccc086a7a63763d6718c49769d5606f0501e0a4442676917e077
463
463
  factory_bot_rails (6.5.1) sha256=d3cc4851eae4dea8a665ec4a4516895045e710554d2b5ac9e68b94d351bc6d68
464
464
  ffi (1.17.3-aarch64-linux-gnu) sha256=28ad573df26560f0aedd8a90c3371279a0b2bd0b4e834b16a2baa10bd7a97068
@@ -3,13 +3,12 @@
3
3
  module Eventsimple
4
4
  class Configuration
5
5
  attr_reader :max_concurrency_retries
6
- attr_writer :metadata_klass, :parent_record_klass
6
+ attr_writer :parent_record_klass
7
7
  attr_accessor :retry_reactor_on_record_not_found, :ui_visible_model_names
8
8
 
9
9
  def initialize
10
10
  @dispatchers = []
11
11
  @max_concurrency_retries = 2
12
- @metadata_klass = 'Eventsimple::Metadata'
13
12
  @parent_record_klass = 'ApplicationRecord'
14
13
  @retry_reactor_on_record_not_found = false
15
14
 
@@ -41,10 +40,6 @@ module Eventsimple
41
40
  @dispatchers_klass_consts ||= @dispatchers.map(&:constantize)
42
41
  end
43
42
 
44
- def metadata_klass
45
- @metadata_klass_const ||= @metadata_klass.constantize
46
- end
47
-
48
43
  def parent_record_klass
49
44
  @parent_record_const ||= @parent_record_klass.constantize
50
45
  end
@@ -5,7 +5,7 @@ module Eventsimple
5
5
  require 'globalid'
6
6
  include GlobalID::Identification
7
7
 
8
- def drives_events_for(aggregate_klass, aggregate_id:, events_namespace: nil)
8
+ def drives_events_for(aggregate_klass, aggregate_id:, events_namespace: nil, metadata_class: nil)
9
9
  begin
10
10
  if defined?(aggregate_klass._aggregate_id) && aggregate_klass.table_exists? && table_exists?
11
11
  raise ArgumentError, "aggregate_id mismatch event:#{aggregate_id} entity:#{aggregate_klass._aggregate_id}" if aggregate_id != aggregate_klass._aggregate_id
@@ -34,10 +34,13 @@ module Eventsimple
34
34
  class_attribute :_on_invalid_transition
35
35
  self._on_invalid_transition = ->(error) { raise error }
36
36
 
37
+ class_attribute :_metadata_klass
38
+ self._metadata_klass = metadata_class.is_a?(Class) ? metadata_class : metadata_class&.to_s&.constantize
39
+
37
40
  self.inheritance_column = 'type'
38
41
  self.store_full_sti_class = false
39
42
 
40
- attribute :metadata, MetadataType.new
43
+ attribute :metadata, MetadataType.new(self)
41
44
  attr_writer :skip_dispatcher
42
45
  attr_writer :skip_apply_check
43
46
 
@@ -164,6 +167,10 @@ module Eventsimple
164
167
  self._on_invalid_transition = block || ->(error) {}
165
168
  end
166
169
 
170
+ def resolve_metadata_klass
171
+ _metadata_klass || Eventsimple::Metadata
172
+ end
173
+
167
174
  # We don't store the full namespaced class name in the events table.
168
175
  # Events for an entity are expected to be namespaced under _events_namespace.
169
176
  def find_sti_class(type_name)
@@ -2,27 +2,36 @@
2
2
 
3
3
  module Eventsimple
4
4
  class MetadataType < ActiveModel::Type::Value
5
+ def initialize(event_class)
6
+ super()
7
+ @event_class = event_class
8
+ end
9
+
5
10
  def type
6
11
  :metadata_type
7
12
  end
8
13
 
14
+ def metadata_klass
15
+ @metadata_klass ||= @event_class.resolve_metadata_klass
16
+ end
17
+
9
18
  def cast_value(value)
10
19
  case value
11
20
  when String
12
21
  decoded = ActiveSupport::JSON.decode(value)
13
22
  return decoded if decoded.empty?
14
23
 
15
- Eventsimple.configuration.metadata_klass.new(decoded)
24
+ metadata_klass.new(decoded)
16
25
  when Hash
17
- Eventsimple.configuration.metadata_klass.new(value)
18
- when Eventsimple.configuration.metadata_klass
26
+ metadata_klass.new(value)
27
+ when metadata_klass
19
28
  value
20
29
  end
21
30
  end
22
31
 
23
32
  def serialize(value)
24
33
  case value
25
- when Hash, Eventsimple.configuration.metadata_klass
34
+ when Hash, metadata_klass
26
35
  ActiveSupport::JSON.encode(value)
27
36
  else
28
37
  super
@@ -32,7 +41,7 @@ module Eventsimple
32
41
  def deserialize(value)
33
42
  decoded = ActiveSupport::JSON.decode(value)
34
43
 
35
- Eventsimple.configuration.metadata_klass.new(decoded)
44
+ metadata_klass.new(decoded)
36
45
  end
37
46
  end
38
47
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Eventsimple
4
- VERSION = '2.2.1'
4
+ VERSION = '2.3.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventsimple
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zulfiqar Ali