active_event_store 0.2.1 → 1.0.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: e89b6923e7b41bac70b72e2f535d964be074e8a22ada023af08899895a286793
4
- data.tar.gz: 29c61f9350f3fc6575e0f95ed799ef164bd275b5c6f7a070f26637793957c6d0
3
+ metadata.gz: 8791927b35712c61094dcb6cc915e2b27912129e675c84230cd6f5271585902e
4
+ data.tar.gz: fe58f1151444dc521caa4666adf06dd97d00bc37882843b1252d776683a98dcf
5
5
  SHA512:
6
- metadata.gz: ae0e00e377d9bebafe57fa92cdfd4c2c6d6fd7005eca1ca7e612400476a2392211d568f5497dfad7299a4445ecb0bbeebdc4e906220521d089da07344fcfa355
7
- data.tar.gz: 305cf18193777091f474193a9d5b4591e3ad505a485caafa2bb127bcc1f0ec5794d159857db0503e3a89639bb6a2c2bcd71fc748038dc5d01a0ef046ebf1d4c0
6
+ metadata.gz: 95f22443b58343d34b93b0400b53c63bf5190ff5f0c8e56c3c96c2e9ebf3d8137bee3136035f7f12d17f8c4488f8bdebef3a4e971eb67dfd17dbafdb48b857ba
7
+ data.tar.gz: c947302a3db94490b5a781f3fb74bacc0b45d437240599766dd33138147b8807119604105b55034482861254463f4a49919dba2689d52eb16599459c2fe15b7a
data/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.0.0 (2021-01-14)
6
+
7
+ - Ruby 2.6+, Rails 6+ and RailsEventStore 2.1+ is required.
5
8
  ## 0.2.1 (2020-09-30)
6
9
 
7
10
  - Fix Active Support load hook name. ([@palkan][])
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2020 Vladimir Dementyev
1
+ Copyright (c) 2020-2021 Vladimir Dementyev
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -21,7 +21,7 @@ Add the gem to your project:
21
21
 
22
22
  ```ruby
23
23
  # Gemfile
24
- gem "active_event_store"
24
+ gem "active_event_store", "~> 1.0"
25
25
  ```
26
26
 
27
27
  Setup database according to the [Rails Event Store docs](https://railseventstore.org/docs/install/#setup-data-model):
@@ -33,8 +33,9 @@ rails db:migrate
33
33
 
34
34
  ### Requirements
35
35
 
36
- - Ruby (MRI) >= 2.5.0
37
- - Rails >= 5.0
36
+ - Ruby (MRI) >= 2.6
37
+ - Rails >= 6.0
38
+ - RailsEventStore >= 2.1
38
39
 
39
40
  ## Usage
40
41
 
@@ -1,11 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "json"
4
+
3
5
  module ActiveEventStore
4
6
  class Config
5
- attr_writer :repository, :job_queue_name, :store_options
7
+ attr_writer :repository, :serializer, :job_queue_name, :store_options
6
8
 
7
9
  def repository
8
- @repository ||= RailsEventStoreActiveRecord::EventRepository.new
10
+ @repository ||= RailsEventStoreActiveRecord::EventRepository.new(serializer: serializer)
11
+ end
12
+
13
+ def serializer
14
+ @serializer ||= JSON
9
15
  end
10
16
 
11
17
  def job_queue_name
@@ -18,7 +18,11 @@ module ActiveEventStore
18
18
  # See https://railseventstore.org/docs/subscribe/#scheduling-async-handlers-after-commit
19
19
  ActiveEventStore.event_store = RailsEventStore::Client.new(
20
20
  dispatcher: RubyEventStore::ComposedDispatcher.new(
21
- RailsEventStore::AfterCommitAsyncDispatcher.new(scheduler: RailsEventStore::ActiveJobScheduler.new),
21
+ RailsEventStore::AfterCommitAsyncDispatcher.new(
22
+ scheduler: RailsEventStore::ActiveJobScheduler.new(
23
+ serializer: ActiveEventStore.config.serializer
24
+ )
25
+ ),
22
26
  RubyEventStore::Dispatcher.new
23
27
  ),
24
28
  repository: ActiveEventStore.config.repository,
@@ -68,20 +68,12 @@ module ActiveEventStore
68
68
  super(**{event_id: event_id, metadata: metadata, data: params}.compact)
69
69
  end
70
70
 
71
- # RES 0.44+
72
- # https://github.com/RailsEventStore/rails_event_store/pull/724
73
- if method_defined?(:event_type)
74
- def event_type
75
- self.class.identifier
76
- end
77
- else
78
- def type
79
- self.class.identifier
80
- end
81
-
82
- alias event_type type
71
+ def type
72
+ self.class.identifier
83
73
  end
84
74
 
75
+ alias_method :event_type, :type
76
+
85
77
  def inspect
86
78
  "#{self.class.name}<#{event_type}##{message_id}>, data: #{data}, metadata: #{metadata}"
87
79
  end
@@ -1,44 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "json"
4
-
5
3
  module ActiveEventStore
6
- using(Module.new do
4
+ using(Module.new {
7
5
  refine Hash do
8
6
  def symbolize_keys
9
7
  RubyEventStore::TransformKeys.symbolize(self)
10
8
  end
11
9
  end
12
- end)
10
+ })
13
11
 
14
12
  # Custom mapper for RES events.
15
13
  #
16
14
  # See https://github.com/RailsEventStore/rails_event_store/blob/v0.35.0/ruby_event_store/lib/ruby_event_store/mappers/default.rb
17
15
  class Mapper
18
- def initialize(mapping:, serializer: JSON)
16
+ def initialize(mapping:, serializer: ActiveEventStore.config.serializer)
19
17
  @serializer = serializer
20
18
  @mapping = mapping
21
19
  end
22
20
 
23
- def event_to_serialized_record(domain_event)
21
+ def event_to_record(domain_event)
24
22
  # lazily add type to mapping
25
23
  # NOTE: use class name instead of a class to handle code reload
26
24
  # in development (to avoid accessing orphaned classes)
27
25
  mapping.register(domain_event.event_type, domain_event.class.name) unless mapping.exist?(domain_event.event_type)
28
26
 
29
- RubyEventStore::SerializedRecord.new(
27
+ RubyEventStore::Record.new(
30
28
  event_id: domain_event.event_id,
31
29
  metadata: serializer.dump(domain_event.metadata.to_h),
32
30
  data: serializer.dump(domain_event.data),
33
- event_type: domain_event.event_type
31
+ event_type: domain_event.event_type,
32
+ timestamp: domain_event.timestamp,
33
+ valid_at: domain_event.valid_at
34
34
  )
35
35
  end
36
36
 
37
- def serialized_record_to_event(record)
38
- event_class = mapping.fetch(record.event_type) do
37
+ def record_to_event(record)
38
+ event_class = mapping.fetch(record.event_type) {
39
39
  raise "Don't know how to deserialize event: \"#{record.event_type}\". " \
40
- "Add explicit mapping: ActiveEventStore.mapper.register \"#{record.event_type}\", \"<Class Name>\""
41
- end
40
+ "Add explicit mapping: ActiveEventStore.mapping.register \"#{record.event_type}\", \"<Class Name>\""
41
+ }
42
42
 
43
43
  Object.const_get(event_class).new(
44
44
  **serializer.load(record.data).symbolize_keys,
@@ -21,7 +21,10 @@ module ActiveEventStore
21
21
  end
22
22
 
23
23
  def matches?(actual_serialized)
24
- actual = ActiveEventStore.event_store.deserialize(actual_serialized)
24
+ actual = ActiveEventStore.event_store.deserialize(
25
+ **actual_serialized,
26
+ serializer: ActiveEventStore.config.serializer
27
+ )
25
28
 
26
29
  actual.event_type == event.event_type && data_matches?(actual.data)
27
30
  end
@@ -62,9 +65,9 @@ module ActiveEventStore
62
65
  end
63
66
 
64
67
  RSpec.configure do |config|
65
- config.include(Module.new do
68
+ config.include(Module.new {
66
69
  def have_enqueued_async_subscriber_for(*args)
67
70
  ActiveEventStore::HaveEnqueuedAsyncSubscriberFor.new(*args)
68
71
  end
69
- end)
72
+ })
70
73
  end
@@ -38,7 +38,7 @@ module ActiveEventStore
38
38
  end
39
39
 
40
40
  def perform(payload)
41
- event = event_store.deserialize(payload)
41
+ event = event_store.deserialize(**payload, serializer: ActiveEventStore.config.serializer)
42
42
 
43
43
  event_store.with_metadata(**event.metadata.to_h) do
44
44
  subscriber.call(event)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveEventStore # :nodoc:
4
- VERSION = "0.2.1"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -24,8 +24,8 @@ module ActiveEventStore
24
24
  @config ||= Config.new
25
25
  end
26
26
 
27
- def subscribe(subscriber = nil, to: nil, sync: false)
28
- subscriber ||= Proc.new
27
+ def subscribe(subscriber = nil, to: nil, sync: false, &block)
28
+ subscriber ||= block
29
29
 
30
30
  to ||= infer_event_from_subscriber(subscriber) if subscriber.is_a?(Module)
31
31
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_event_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-30 00:00:00.000000000 Z
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails_event_store
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.42.0
19
+ version: 2.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.42.0
26
+ version: 2.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -111,7 +111,7 @@ metadata:
111
111
  documentation_uri: http://github.com/palkan/active_event_store
112
112
  homepage_uri: http://github.com/palkan/active_event_store
113
113
  source_code_uri: http://github.com/palkan/active_event_store
114
- post_install_message:
114
+ post_install_message:
115
115
  rdoc_options: []
116
116
  require_paths:
117
117
  - lib
@@ -119,15 +119,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
- version: '2.5'
122
+ version: '2.6'
123
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - ">="
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
128
  requirements: []
129
- rubygems_version: 3.0.6
130
- signing_key:
129
+ rubygems_version: 3.2.15
130
+ signing_key:
131
131
  specification_version: 4
132
132
  summary: Rails Event Store in a more Rails way
133
133
  test_files: []