ruby_event_store 2.2.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruby_event_store/batch_enumerator.rb +3 -3
  3. data/lib/ruby_event_store/broker.rb +5 -4
  4. data/lib/ruby_event_store/client.rb +75 -46
  5. data/lib/ruby_event_store/composed_dispatcher.rb +1 -3
  6. data/lib/ruby_event_store/correlated_commands.rb +4 -15
  7. data/lib/ruby_event_store/errors.rb +11 -10
  8. data/lib/ruby_event_store/event.rb +9 -14
  9. data/lib/ruby_event_store/expected_version.rb +3 -7
  10. data/lib/ruby_event_store/in_memory_repository.rb +100 -37
  11. data/lib/ruby_event_store/instrumented_dispatcher.rb +11 -2
  12. data/lib/ruby_event_store/instrumented_repository.rb +13 -8
  13. data/lib/ruby_event_store/link_by_metadata.rb +4 -21
  14. data/lib/ruby_event_store/mappers/default.rb +6 -4
  15. data/lib/ruby_event_store/mappers/encryption_key.rb +7 -16
  16. data/lib/ruby_event_store/mappers/encryption_mapper.rb +6 -6
  17. data/lib/ruby_event_store/mappers/forgotten_data.rb +1 -1
  18. data/lib/ruby_event_store/mappers/in_memory_encryption_key_repository.rb +1 -1
  19. data/lib/ruby_event_store/mappers/null_mapper.rb +0 -1
  20. data/lib/ruby_event_store/mappers/pipeline.rb +3 -10
  21. data/lib/ruby_event_store/mappers/pipeline_mapper.rb +1 -0
  22. data/lib/ruby_event_store/mappers/transformation/domain_event.rb +23 -13
  23. data/lib/ruby_event_store/mappers/transformation/encryption.rb +21 -25
  24. data/lib/ruby_event_store/mappers/transformation/event_class_remapper.rb +6 -5
  25. data/lib/ruby_event_store/mappers/transformation/stringify_metadata_keys.rb +6 -5
  26. data/lib/ruby_event_store/mappers/transformation/symbolize_metadata_keys.rb +6 -5
  27. data/lib/ruby_event_store/mappers/transformation/upcast.rb +2 -6
  28. data/lib/ruby_event_store/metadata.rb +46 -17
  29. data/lib/ruby_event_store/projection.rb +12 -20
  30. data/lib/ruby_event_store/record.rb +14 -26
  31. data/lib/ruby_event_store/serialized_record.rb +14 -26
  32. data/lib/ruby_event_store/serializers/yaml.rb +17 -0
  33. data/lib/ruby_event_store/spec/broker_lint.rb +38 -28
  34. data/lib/ruby_event_store/spec/event_lint.rb +10 -10
  35. data/lib/ruby_event_store/spec/event_repository_lint.rb +745 -741
  36. data/lib/ruby_event_store/spec/mapper_lint.rb +2 -2
  37. data/lib/ruby_event_store/spec/subscriptions_lint.rb +58 -57
  38. data/lib/ruby_event_store/specification.rb +20 -16
  39. data/lib/ruby_event_store/specification_reader.rb +2 -3
  40. data/lib/ruby_event_store/specification_result.rb +52 -46
  41. data/lib/ruby_event_store/stream.rb +3 -7
  42. data/lib/ruby_event_store/subscriptions.rb +14 -15
  43. data/lib/ruby_event_store/transform_keys.rb +1 -1
  44. data/lib/ruby_event_store/version.rb +1 -1
  45. data/lib/ruby_event_store.rb +44 -43
  46. metadata +6 -4
@@ -3,8 +3,8 @@ module RubyEventStore
3
3
  specify "event_to_record returns instance of Record" do
4
4
  record = mapper.event_to_record(domain_event)
5
5
 
6
- expect(record).to be_kind_of(Record)
7
- expect(record.event_id).to eq(domain_event.event_id)
6
+ expect(record).to be_kind_of(Record)
7
+ expect(record.event_id).to eq(domain_event.event_id)
8
8
  expect(record.event_type).to eq(domain_event.event_type)
9
9
  end
10
10
 
@@ -17,109 +17,110 @@ RSpec.shared_examples :subscriptions do |subscriptions_class|
17
17
 
18
18
  subject(:subscriptions) { subscriptions_class.new }
19
19
 
20
- it 'returns all subscribed handlers' do
21
- handler = TestHandler.new
20
+ it "returns all subscribed handlers" do
21
+ handler = TestHandler.new
22
22
  another_handler = TestHandler.new
23
- global_handler = TestHandler.new
23
+ global_handler = TestHandler.new
24
24
 
25
25
  subscriptions.add_subscription(handler, [Test1DomainEvent, Test3DomainEvent])
26
26
  subscriptions.add_subscription(another_handler, [Test2DomainEvent])
27
27
  subscriptions.add_global_subscription(global_handler)
28
28
 
29
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([handler, global_handler])
30
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([another_handler, global_handler])
31
- expect(subscriptions.all_for('Test3DomainEvent')).to eq([handler, global_handler])
29
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([handler, global_handler])
30
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([another_handler, global_handler])
31
+ expect(subscriptions.all_for("Test3DomainEvent")).to eq([handler, global_handler])
32
32
  end
33
33
 
34
- it 'returns subscribed thread handlers' do
35
- handler = TestHandler.new
34
+ it "returns subscribed thread handlers" do
35
+ handler = TestHandler.new
36
36
  another_handler = TestHandler.new
37
- global_handler = TestHandler.new
37
+ global_handler = TestHandler.new
38
38
 
39
39
  subscriptions.add_thread_subscription(handler, [Test1DomainEvent, Test3DomainEvent])
40
40
  subscriptions.add_thread_subscription(another_handler, [Test2DomainEvent])
41
41
  subscriptions.add_thread_global_subscription(global_handler)
42
- t = Thread.new do
43
- subscriptions.add_thread_subscription(handler, [Test2DomainEvent])
44
- subscriptions.add_thread_global_subscription(another_handler)
45
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([another_handler, handler])
46
- end
47
-
48
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([global_handler, handler])
49
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([global_handler, another_handler])
50
- expect(subscriptions.all_for('Test3DomainEvent')).to eq([global_handler, handler])
42
+ t =
43
+ Thread.new do
44
+ subscriptions.add_thread_subscription(handler, [Test2DomainEvent])
45
+ subscriptions.add_thread_global_subscription(another_handler)
46
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([another_handler, handler])
47
+ end
48
+
49
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([global_handler, handler])
50
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([global_handler, another_handler])
51
+ expect(subscriptions.all_for("Test3DomainEvent")).to eq([global_handler, handler])
51
52
  t.join
52
53
  end
53
54
 
54
- it 'returns lambda as an output of global subscribe methods' do
55
- handler = TestHandler.new
55
+ it "returns lambda as an output of global subscribe methods" do
56
+ handler = TestHandler.new
56
57
  result = subscriptions.add_global_subscription(handler)
57
58
  expect(result).to respond_to(:call)
58
59
  end
59
60
 
60
- it 'returns lambda as an output of subscribe methods' do
61
- handler = TestHandler.new
62
- result = subscriptions.add_subscription(handler, [Test1DomainEvent, Test2DomainEvent])
61
+ it "returns lambda as an output of subscribe methods" do
62
+ handler = TestHandler.new
63
+ result = subscriptions.add_subscription(handler, [Test1DomainEvent, Test2DomainEvent])
63
64
  expect(result).to respond_to(:call)
64
65
  end
65
66
 
66
- it 'revokes global subscription' do
67
- handler = TestHandler.new
67
+ it "revokes global subscription" do
68
+ handler = TestHandler.new
68
69
 
69
- revoke = subscriptions.add_global_subscription(handler)
70
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([handler])
71
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([handler])
70
+ revoke = subscriptions.add_global_subscription(handler)
71
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([handler])
72
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([handler])
72
73
  revoke.()
73
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([])
74
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([])
74
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([])
75
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([])
75
76
  end
76
77
 
77
- it 'revokes subscription' do
78
- handler = TestHandler.new
78
+ it "revokes subscription" do
79
+ handler = TestHandler.new
79
80
 
80
- revoke = subscriptions.add_subscription(handler, [Test1DomainEvent, Test2DomainEvent])
81
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([handler])
82
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([handler])
81
+ revoke = subscriptions.add_subscription(handler, [Test1DomainEvent, Test2DomainEvent])
82
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([handler])
83
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([handler])
83
84
  revoke.()
84
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([])
85
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([])
85
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([])
86
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([])
86
87
  end
87
88
 
88
- it 'revokes thread global subscription' do
89
- handler = TestHandler.new
89
+ it "revokes thread global subscription" do
90
+ handler = TestHandler.new
90
91
 
91
- revoke = subscriptions.add_thread_global_subscription(handler)
92
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([handler])
93
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([handler])
92
+ revoke = subscriptions.add_thread_global_subscription(handler)
93
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([handler])
94
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([handler])
94
95
  revoke.()
95
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([])
96
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([])
96
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([])
97
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([])
97
98
  end
98
99
 
99
- it 'revokes thread subscription' do
100
- handler = TestHandler.new
100
+ it "revokes thread subscription" do
101
+ handler = TestHandler.new
101
102
 
102
- revoke = subscriptions.add_thread_subscription(handler, [Test1DomainEvent, Test2DomainEvent])
103
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([handler])
104
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([handler])
103
+ revoke = subscriptions.add_thread_subscription(handler, [Test1DomainEvent, Test2DomainEvent])
104
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([handler])
105
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([handler])
105
106
  revoke.()
106
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([])
107
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([])
107
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([])
108
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([])
108
109
  end
109
110
 
110
- it 'subscribes by type of event which is a String' do
111
- handler = TestHandler.new
111
+ it "subscribes by type of event which is a String" do
112
+ handler = TestHandler.new
112
113
  subscriptions.add_subscription(handler, ["Test1DomainEvent"])
113
114
  subscriptions.add_thread_subscription(handler, ["Test1DomainEvent"])
114
115
 
115
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([handler, handler])
116
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([handler, handler])
116
117
  end
117
118
 
118
- it 'subscribes by type of event which is a class' do
119
- handler = TestHandler.new
119
+ it "subscribes by type of event which is a class" do
120
+ handler = TestHandler.new
120
121
  subscriptions.add_subscription(handler, [Test1DomainEvent])
121
122
  subscriptions.add_thread_subscription(handler, [Test1DomainEvent])
122
123
 
123
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([handler, handler])
124
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([handler, handler])
124
125
  end
125
126
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyEventStore
4
-
5
4
  # Used for building and executing the query specification.
6
5
  class Specification
7
6
  DEFAULT_BATCH_SIZE = 100
7
+
8
8
  # @api private
9
9
  # @private
10
10
  def initialize(reader, result = SpecificationResult.new)
@@ -53,7 +53,7 @@ module RubyEventStore
53
53
  Specification.new(
54
54
  reader,
55
55
  result.dup do |r|
56
- r.older_than = time
56
+ r.older_than = time
57
57
  r.older_than_or_equal = nil
58
58
  end
59
59
  )
@@ -69,7 +69,7 @@ module RubyEventStore
69
69
  Specification.new(
70
70
  reader,
71
71
  result.dup do |r|
72
- r.older_than = nil
72
+ r.older_than = nil
73
73
  r.older_than_or_equal = time
74
74
  end
75
75
  )
@@ -86,7 +86,7 @@ module RubyEventStore
86
86
  reader,
87
87
  result.dup do |r|
88
88
  r.newer_than_or_equal = nil
89
- r.newer_than = time
89
+ r.newer_than = time
90
90
  end
91
91
  )
92
92
  end
@@ -102,7 +102,7 @@ module RubyEventStore
102
102
  reader,
103
103
  result.dup do |r|
104
104
  r.newer_than_or_equal = time
105
- r.newer_than = nil
105
+ r.newer_than = nil
106
106
  end
107
107
  )
108
108
  end
@@ -125,7 +125,7 @@ module RubyEventStore
125
125
  #
126
126
  # @return [Specification]
127
127
  def as_at
128
- Specification.new(reader, result.dup { |r| r.time_sort_by = :as_at})
128
+ Specification.new(reader, result.dup { |r| r.time_sort_by = :as_at })
129
129
  end
130
130
 
131
131
  # Sets the order of time sorting using validity time
@@ -171,9 +171,7 @@ module RubyEventStore
171
171
  def each_batch
172
172
  return to_enum(:each_batch) unless block_given?
173
173
 
174
- reader.each(in_batches(result.batch_size).result) do |batch|
175
- yield batch
176
- end
174
+ reader.each(in_batches(result.batch_size).result) { |batch| yield batch }
177
175
  end
178
176
 
179
177
  # Executes the query based on the specification built up to this point.
@@ -185,9 +183,7 @@ module RubyEventStore
185
183
  def each
186
184
  return to_enum unless block_given?
187
185
 
188
- each_batch do |batch|
189
- batch.each { |event| yield event }
190
- end
186
+ each_batch { |batch| batch.each { |event| yield event } }
191
187
  end
192
188
 
193
189
  # Executes the query based on the specification built up to this point
@@ -242,9 +238,15 @@ module RubyEventStore
242
238
  # @param batch_size [Integer] number of events to read in a single batch
243
239
  # @return [Specification]
244
240
  def in_batches(batch_size = DEFAULT_BATCH_SIZE)
245
- Specification.new(reader, result.dup { |r| r.read_as = :batch; r.batch_size = batch_size })
241
+ Specification.new(
242
+ reader,
243
+ result.dup do |r|
244
+ r.read_as = :batch
245
+ r.batch_size = batch_size
246
+ end
247
+ )
246
248
  end
247
- alias :in_batches_of :in_batches
249
+ alias in_batches_of in_batches
248
250
 
249
251
  # Specifies that only first event should be read.
250
252
  # {http://railseventstore.org/docs/read/ Find out more}.
@@ -286,7 +288,7 @@ module RubyEventStore
286
288
  # @types [Class, Array(Class)] types of event to look for.
287
289
  # @return [Specification]
288
290
  def of_type(*types)
289
- Specification.new(reader, result.dup{ |r| r.with_types = types.flatten })
291
+ Specification.new(reader, result.dup { |r| r.with_types = types.flatten })
290
292
  end
291
293
  alias_method :of_types, :of_type
292
294
 
@@ -296,7 +298,7 @@ module RubyEventStore
296
298
  # @param event_ids [Array(String)] ids of event to look for.
297
299
  # @return [Specification]
298
300
  def with_id(event_ids)
299
- Specification.new(reader, result.dup{ |r| r.with_ids = event_ids })
301
+ Specification.new(reader, result.dup { |r| r.with_ids = event_ids })
300
302
  end
301
303
 
302
304
  # Reads single event from repository.
@@ -331,7 +333,9 @@ module RubyEventStore
331
333
  end
332
334
 
333
335
  attr_reader :result
336
+
334
337
  private
338
+
335
339
  attr_reader :reader
336
340
  end
337
341
  end
@@ -20,9 +20,7 @@ module RubyEventStore
20
20
  # @api private
21
21
  # @private
22
22
  def each(specification_result)
23
- repository.read(specification_result).each do |batch|
24
- yield batch.map { |record| mapper.record_to_event(record) }
25
- end
23
+ repository.read(specification_result).each { |batch| yield batch.map { |record| mapper.record_to_event(record) } }
26
24
  end
27
25
 
28
26
  # @api private
@@ -38,6 +36,7 @@ module RubyEventStore
38
36
  end
39
37
 
40
38
  private
39
+
41
40
  attr_reader :repository, :mapper
42
41
  end
43
42
  end
@@ -2,51 +2,56 @@
2
2
 
3
3
  module RubyEventStore
4
4
  class SpecificationResult
5
- def initialize(direction: :forward,
6
- start: nil,
7
- stop: nil,
8
- older_than: nil,
9
- older_than_or_equal: nil,
10
- newer_than: nil,
11
- newer_than_or_equal: nil,
12
- time_sort_by: nil,
13
- count: nil,
14
- stream: Stream.new(GLOBAL_STREAM),
15
- read_as: :all,
16
- batch_size: Specification::DEFAULT_BATCH_SIZE,
17
- with_ids: nil,
18
- with_types: nil)
19
- @attributes = Struct.new(
20
- :direction,
21
- :start,
22
- :stop,
23
- :older_than,
24
- :older_than_or_equal,
25
- :newer_than,
26
- :newer_than_or_equal,
27
- :time_sort_by,
28
- :count,
29
- :stream,
30
- :read_as,
31
- :batch_size,
32
- :with_ids,
33
- :with_types
34
- ).new(
35
- direction,
36
- start,
37
- stop,
38
- older_than,
39
- older_than_or_equal,
40
- newer_than,
41
- newer_than_or_equal,
42
- time_sort_by,
43
- count,
44
- stream,
45
- read_as,
46
- batch_size,
47
- with_ids,
48
- with_types
49
- )
5
+ def initialize(
6
+ direction: :forward,
7
+ start: nil,
8
+ stop: nil,
9
+ older_than: nil,
10
+ older_than_or_equal: nil,
11
+ newer_than: nil,
12
+ newer_than_or_equal: nil,
13
+ time_sort_by: nil,
14
+ count: nil,
15
+ stream: Stream.new(GLOBAL_STREAM),
16
+ read_as: :all,
17
+ batch_size: Specification::DEFAULT_BATCH_SIZE,
18
+ with_ids: nil,
19
+ with_types: nil
20
+ )
21
+ @attributes =
22
+ Struct
23
+ .new(
24
+ :direction,
25
+ :start,
26
+ :stop,
27
+ :older_than,
28
+ :older_than_or_equal,
29
+ :newer_than,
30
+ :newer_than_or_equal,
31
+ :time_sort_by,
32
+ :count,
33
+ :stream,
34
+ :read_as,
35
+ :batch_size,
36
+ :with_ids,
37
+ :with_types
38
+ )
39
+ .new(
40
+ direction,
41
+ start,
42
+ stop,
43
+ older_than,
44
+ older_than_or_equal,
45
+ newer_than,
46
+ newer_than_or_equal,
47
+ time_sort_by,
48
+ count,
49
+ stream,
50
+ read_as,
51
+ batch_size,
52
+ with_ids,
53
+ with_types
54
+ )
50
55
  freeze
51
56
  end
52
57
 
@@ -282,11 +287,12 @@ module RubyEventStore
282
287
  attributes.read_as,
283
288
  batch_size,
284
289
  with_ids,
285
- with_types,
290
+ with_types
286
291
  ].hash ^ BIG_VALUE
287
292
  end
288
293
 
289
294
  private
295
+
290
296
  attr_reader :attributes
291
297
 
292
298
  def get_direction
@@ -15,19 +15,15 @@ module RubyEventStore
15
15
 
16
16
  BIG_VALUE = 0b111111100100000010010010110011101011000101010101001100100110011
17
17
  def hash
18
- [
19
- self.class,
20
- name
21
- ].hash ^ BIG_VALUE
18
+ [self.class, name].hash ^ BIG_VALUE
22
19
  end
23
20
 
24
21
  def ==(other_stream)
25
- other_stream.instance_of?(self.class) &&
26
- other_stream.name.eql?(name)
22
+ other_stream.instance_of?(self.class) && other_stream.name.eql?(name)
27
23
  end
28
24
 
29
25
  alias_method :eql?, :==
30
26
 
31
27
  private_constant :BIG_VALUE
32
28
  end
33
- end
29
+ end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'concurrent'
3
+ require "concurrent"
4
4
 
5
5
  module RubyEventStore
6
6
  class Subscriptions
7
7
  def initialize(event_type_resolver: default_event_type_resolver)
8
8
  @event_type_resolver = event_type_resolver
9
- @local = LocalSubscriptions.new
9
+ @local = LocalSubscriptions.new
10
10
  @global = GlobalSubscriptions.new
11
11
  @thread = ThreadSubscriptions.new
12
12
  end
@@ -28,12 +28,13 @@ module RubyEventStore
28
28
  end
29
29
 
30
30
  def all_for(event_type)
31
- [local, global, thread].map{|r| r.all_for(event_type)}.reduce(&:+)
31
+ [local, global, thread].map { |r| r.all_for(event_type) }.reduce(&:+)
32
32
  end
33
33
 
34
34
  attr_reader :event_type_resolver
35
35
 
36
36
  private
37
+
37
38
  attr_reader :local, :global, :thread
38
39
 
39
40
  def default_event_type_resolver
@@ -50,24 +51,24 @@ module RubyEventStore
50
51
 
51
52
  class ThreadSubscriptions
52
53
  def initialize
53
- @local = ThreadLocalSubscriptions.new
54
+ @local = ThreadLocalSubscriptions.new
54
55
  @global = ThreadGlobalSubscriptions.new
55
56
  end
56
57
  attr_reader :local, :global
57
58
 
58
59
  def all_for(event_type)
59
- [global, local].map{|r| r.all_for(event_type)}.reduce(&:+)
60
+ [global, local].map { |r| r.all_for(event_type) }.reduce(&:+)
60
61
  end
61
62
  end
62
63
 
63
64
  class LocalSubscriptions
64
65
  def initialize
65
- @subscriptions = Hash.new {|hsh, key| hsh[key] = [] }
66
+ @subscriptions = Hash.new { |hsh, key| hsh[key] = [] }
66
67
  end
67
68
 
68
69
  def add(subscription, event_types)
69
- event_types.each{ |type| @subscriptions[type] << subscription }
70
- ->() {event_types.each{ |type| @subscriptions.fetch(type).delete(subscription) } }
70
+ event_types.each { |type| @subscriptions[type] << subscription }
71
+ -> { event_types.each { |type| @subscriptions.fetch(type).delete(subscription) } }
71
72
  end
72
73
 
73
74
  def all_for(event_type)
@@ -82,7 +83,7 @@ module RubyEventStore
82
83
 
83
84
  def add(subscription)
84
85
  @subscriptions << subscription
85
- ->() { @subscriptions.delete(subscription) }
86
+ -> { @subscriptions.delete(subscription) }
86
87
  end
87
88
 
88
89
  def all_for(_event_type)
@@ -92,14 +93,12 @@ module RubyEventStore
92
93
 
93
94
  class ThreadLocalSubscriptions
94
95
  def initialize
95
- @subscriptions = Concurrent::ThreadLocalVar.new do
96
- Hash.new {|hsh, key| hsh[key] = [] }
97
- end
96
+ @subscriptions = Concurrent::ThreadLocalVar.new { Hash.new { |hsh, key| hsh[key] = [] } }
98
97
  end
99
98
 
100
99
  def add(subscription, event_types)
101
- event_types.each{ |type| @subscriptions.value[type] << subscription }
102
- ->() {event_types.each{ |type| @subscriptions.value.fetch(type).delete(subscription) } }
100
+ event_types.each { |type| @subscriptions.value[type] << subscription }
101
+ -> { event_types.each { |type| @subscriptions.value.fetch(type).delete(subscription) } }
103
102
  end
104
103
 
105
104
  def all_for(event_type)
@@ -114,7 +113,7 @@ module RubyEventStore
114
113
 
115
114
  def add(subscription)
116
115
  @subscriptions.value += [subscription]
117
- ->() { @subscriptions.value -= [subscription] }
116
+ -> { @subscriptions.value -= [subscription] }
118
117
  end
119
118
 
120
119
  def all_for(_event_type)
@@ -20,7 +20,7 @@ module RubyEventStore
20
20
  when Hash
21
21
  deep_transform(v, &block)
22
22
  when Array
23
- v.map{|i| Hash === i ? deep_transform(i, &block) : i}
23
+ v.map { |i| Hash === i ? deep_transform(i, &block) : i }
24
24
  else
25
25
  v
26
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyEventStore
4
- VERSION = "2.2.0"
4
+ VERSION = "2.4.1"
5
5
  end