ruby_event_store 0.28.2 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0def047b412b8c6bf085f4dd64676ec4c83914669f7130dd8222c3bacf54388
4
- data.tar.gz: fa118f1c24a9341f9cc268dc11f1f564ce19dd449f568d33cfcda7c8a5e0c2fd
3
+ metadata.gz: dce5f67de62e85755060ade796d9f07674197175c867ea6028dca2b9fd730791
4
+ data.tar.gz: 95fb9ef4100c3fd2179cb0c5ff7e77e9c31801c68cc5872eb020433e448d1668
5
5
  SHA512:
6
- metadata.gz: d14dce04d4bed5741513e671583518ee9c5556205d88025a9e3147198e7721b53392c88e8463505151cfea28d88f31b0b3fa5c603b31ef7d81b897be2a72626e
7
- data.tar.gz: b46d4bf827500892af75fa53827761ef8cde5fbf9bcb96dc8c1a08eeb8eb1993d276ac3927503fbcf557dd85deab88db3a42bd5bff2a049699f5dc374487ffff
6
+ metadata.gz: eee87e104fc965fe7c4e7768ba97424d072d816c107d7ed70a8317c86e6b848f532808626851cd3acd9e7ef5f7f3a4fcfa224baa47b631b97b6be6968e82c92c
7
+ data.tar.gz: 4aa91e0bf722675f60dff89fcf1b42ab47faf82e95ab4087017f3538b2ea919c814aa63692d467eab69f12ece43efd516bd73ae5c7a3da51af6bfad2f5bbbc60
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
- gem 'pry'
4
3
  gem 'protobuf_nested_struct'
@@ -10,6 +10,7 @@ module RubyEventStore
10
10
  @mapper = mapper
11
11
  @event_broker = event_broker
12
12
  @page_size = page_size
13
+ warn "`RubyEventStore::Client#metadata_proc` has been deprecated. Use `RubyEventStore::Client#with_metadata` instead." if metadata_proc
13
14
  @metadata_proc = metadata_proc
14
15
  @clock = clock
15
16
  end
@@ -171,6 +172,14 @@ module RubyEventStore
171
172
  Within.new(block, event_broker)
172
173
  end
173
174
 
175
+ def with_metadata(metadata, &block)
176
+ previous_metadata = metadata()
177
+ self.metadata = (previous_metadata || {}).merge(metadata)
178
+ block.call if block_given?
179
+ ensure
180
+ self.metadata = previous_metadata
181
+ end
182
+
174
183
  private
175
184
 
176
185
  def serialized_events(events)
@@ -198,13 +207,26 @@ module RubyEventStore
198
207
  end
199
208
 
200
209
  def enrich_event_metadata(event)
201
- event.metadata[:timestamp] ||= clock.()
202
210
  if metadata_proc
203
211
  md = metadata_proc.call || {}
204
212
  md.each{|k,v| event.metadata[k]=(v) }
205
213
  end
214
+ if metadata
215
+ metadata.each { |key, value| event.metadata[key] = value }
216
+ end
217
+ event.metadata[:timestamp] ||= clock.call
206
218
  end
207
219
 
208
220
  attr_reader :repository, :mapper, :event_broker, :clock, :metadata_proc, :page_size
221
+
222
+ protected
223
+
224
+ def metadata
225
+ Thread.current["ruby_event_store_#{hash}"]
226
+ end
227
+
228
+ def metadata=(value)
229
+ Thread.current["ruby_event_store_#{hash}"] = value
230
+ end
209
231
  end
210
232
  end
@@ -31,14 +31,13 @@ module RubyEventStore
31
31
 
32
32
  attr_reader :result
33
33
 
34
- def initialize(repository)
34
+ def initialize(repository, result = Result.new(:forward, :head, NO_LIMIT, Stream.new(GLOBAL_STREAM)))
35
35
  @repository = repository
36
- @result = Result.new(:forward, :head, NO_LIMIT, Stream.new(GLOBAL_STREAM))
36
+ @result = result
37
37
  end
38
38
 
39
39
  def stream(stream_name)
40
- result.stream = Stream.new(stream_name)
41
- self
40
+ Specification.new(repository, result.dup.tap { |r| r.stream = Stream.new(stream_name) })
42
41
  end
43
42
 
44
43
  def from(start)
@@ -47,30 +46,29 @@ module RubyEventStore
47
46
  raise InvalidPageStart unless [:head].include?(start)
48
47
  else
49
48
  raise InvalidPageStart if start.nil? || start.empty?
50
- raise EventNotFound.new(start) unless @repository.has_event?(start)
49
+ raise EventNotFound.new(start) unless repository.has_event?(start)
51
50
  end
52
- result.start = start
53
- self
51
+ Specification.new(repository, result.dup.tap { |r| r.start = start })
54
52
  end
55
53
 
56
54
  def forward
57
- result.direction = :forward
58
- self
55
+ Specification.new(repository, result.dup.tap { |r| r.direction = :forward })
59
56
  end
60
57
 
61
58
  def backward
62
- result.direction = :backward
63
- self
59
+ Specification.new(repository, result.dup.tap { |r| r.direction = :backward })
64
60
  end
65
61
 
66
62
  def limit(count)
67
63
  raise InvalidPageSize unless count && count > 0
68
- result.count = count
69
- self
64
+ Specification.new(repository, result.dup.tap { |r| r.count = count })
70
65
  end
71
66
 
72
67
  def each
73
- @repository.read(result)
68
+ repository.read(result)
74
69
  end
70
+
71
+ private
72
+ attr_reader :repository
75
73
  end
76
74
  end
@@ -1,3 +1,3 @@
1
1
  module RubyEventStore
2
- VERSION = "0.28.2"
2
+ VERSION = "0.29.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_event_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.2
4
+ version: 0.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency