ruby_event_store 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/ruby_event_store/constants.rb +1 -0
- data/lib/ruby_event_store/projection.rb +27 -4
- data/lib/ruby_event_store/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 614b77bc975d7069bd524039c78df5291f68e0be
|
4
|
+
data.tar.gz: d975aaaa8bb77c64a74917f8e4c7d85158b5862b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4262004b0bb3326f3bea2d6d001dd5e1e61eeb0a202b00c9708cb9130f4ef3f8d578ba45884e5ce0e22e701fbea56affc0f781b45ec175c6dea700b75c66ccbc
|
7
|
+
data.tar.gz: c6de5b7aa1817100b9020a7980ac3e56107f18a20261b555291025f502d6e78577ef55ee2fb27e27a18be3e0311b5b033057186b7b04e45a229a8440dd4aecbd
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
module RubyEventStore
|
2
3
|
class Projection
|
3
4
|
private_class_method :new
|
@@ -7,7 +8,11 @@ module RubyEventStore
|
|
7
8
|
new(streams)
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
+
def self.from_all_streams
|
12
|
+
new
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(streams = [])
|
11
16
|
@streams = streams
|
12
17
|
@handlers = Hash.new { ->(_, _) {} }
|
13
18
|
@init = -> { Hash.new }
|
@@ -41,13 +46,31 @@ module RubyEventStore
|
|
41
46
|
handlers.keys
|
42
47
|
end
|
43
48
|
|
44
|
-
def call(event_store)
|
45
|
-
streams.
|
46
|
-
event_store
|
49
|
+
def call(event_store, start = :head, count = PAGE_SIZE)
|
50
|
+
if streams.any?
|
51
|
+
reduce_from_streams(event_store, start, count)
|
52
|
+
else
|
53
|
+
reduce_from_all_streams(event_store, start, count)
|
47
54
|
end
|
48
55
|
end
|
49
56
|
|
50
57
|
private
|
58
|
+
def reduce_from_streams(event_store, start, count)
|
59
|
+
raise ArgumentError.new('Start must be an array with event ids or :head') unless (start.instance_of?(Array) && start.size === streams.size) || start === :head
|
60
|
+
streams.zip(start_events(start)).reduce(initial_state) do |state, (stream_name, start_event_id)|
|
61
|
+
event_store.read_events_forward(stream_name, start_event_id, count).reduce(state, &method(:transition))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def reduce_from_all_streams(event_store, start, count)
|
66
|
+
raise ArgumentError.new('Start must be valid event id or :head') unless start.instance_of?(String) || start === :head
|
67
|
+
event_store.read_all_streams_forward(start, count).reduce(initial_state, &method(:transition))
|
68
|
+
end
|
69
|
+
|
70
|
+
def start_events(start)
|
71
|
+
start === :head ? Array.new(streams.size) { :head } : start
|
72
|
+
end
|
73
|
+
|
51
74
|
def transition(state, event)
|
52
75
|
handlers[event.class].(state, event)
|
53
76
|
state
|