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 +4 -4
- data/Gemfile +0 -1
- data/lib/ruby_event_store/client.rb +23 -1
- data/lib/ruby_event_store/specification.rb +12 -14
- data/lib/ruby_event_store/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dce5f67de62e85755060ade796d9f07674197175c867ea6028dca2b9fd730791
|
4
|
+
data.tar.gz: 95fb9ef4100c3fd2179cb0c5ff7e77e9c31801c68cc5872eb020433e448d1668
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eee87e104fc965fe7c4e7768ba97424d072d816c107d7ed70a8317c86e6b848f532808626851cd3acd9e7ef5f7f3a4fcfa224baa47b631b97b6be6968e82c92c
|
7
|
+
data.tar.gz: 4aa91e0bf722675f60dff89fcf1b42ab47faf82e95ab4087017f3538b2ea919c814aa63692d467eab69f12ece43efd516bd73ae5c7a3da51af6bfad2f5bbbc60
|
data/Gemfile
CHANGED
@@ -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 =
|
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
|
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
|
-
|
68
|
+
repository.read(result)
|
74
69
|
end
|
70
|
+
|
71
|
+
private
|
72
|
+
attr_reader :repository
|
75
73
|
end
|
76
74
|
end
|