ruby_event_store 0.22.1 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +9 -1
- data/lib/ruby_event_store/projection.rb +41 -4
- data/lib/ruby_event_store/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1f525f7137ed8264fed0f4a6a9a6dbbdd61eb8a
|
4
|
+
data.tar.gz: 7ec64d4322faa52c1a4801536043cd2fd26aa2a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ce82455b9dc557beb7ce246e8c4b01f6cf456b634c7fafee9b477b275e6d9c6823e8214e89ed12399834fc2c0424fe9a4c35e5554c2d546f3bb77c59290eba5
|
7
|
+
data.tar.gz: 26ae782dc1817cf2d547d4a1fbf5b1d5c3b9ab8bc31057658622eea77ae1b1de87a7fc59dfdb10ed32d9121e3e72a93ec835d04b7da39f6a96acd4f10bf98b32
|
data/Makefile
CHANGED
@@ -10,7 +10,15 @@ test: ## Run tests
|
|
10
10
|
|
11
11
|
mutate: test ## Run mutation tests
|
12
12
|
@echo "Running mutation tests - only 100% free mutation will be accepted"
|
13
|
-
@bundle exec mutant --include lib --require ruby_event_store --use rspec "RubyEventStore*"
|
13
|
+
@bundle exec mutant --include lib --require ruby_event_store --use rspec "RubyEventStore*" \
|
14
|
+
--ignore-subject "RubyEventStore.const_missing" \
|
15
|
+
--ignore-subject "RubyEventStore::InMemoryRepository#append_with_synchronize" \
|
16
|
+
--ignore-subject "RubyEventStore::InMemoryRepository#normalize_to_array" \
|
17
|
+
--ignore-subject "RubyEventStore::Client#normalize_to_array" \
|
18
|
+
--ignore-subject "RubyEventStore::SerializedRecord" \
|
19
|
+
--ignore-subject "RubyEventStore::Projection#read_events_from_stream" \
|
20
|
+
--ignore-subject "RubyEventStore::Projection#read_events_from_all_streams"
|
21
|
+
|
14
22
|
|
15
23
|
build:
|
16
24
|
@gem build -V ruby_event_store.gemspec
|
@@ -58,16 +58,53 @@ module RubyEventStore
|
|
58
58
|
end
|
59
59
|
|
60
60
|
private
|
61
|
+
def valid_starting_point?(start)
|
62
|
+
return true if start === :head
|
63
|
+
if streams.any?
|
64
|
+
(start.instance_of?(Array) && start.size === streams.size)
|
65
|
+
else
|
66
|
+
start.instance_of?(String)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def reduce_events(events, initial_state)
|
71
|
+
events.reduce(initial_state, &method(:transition))
|
72
|
+
end
|
73
|
+
|
74
|
+
def read_events_from_stream(event_store, stream_name, start, count)
|
75
|
+
event_store.read_events_forward(stream_name, start: start, count: count)
|
76
|
+
end
|
77
|
+
|
61
78
|
def reduce_from_streams(event_store, start, count)
|
62
|
-
raise ArgumentError.new('Start must be an array with event ids or :head') unless
|
79
|
+
raise ArgumentError.new('Start must be an array with event ids or :head') unless valid_starting_point?(start)
|
63
80
|
streams.zip(start_events(start)).reduce(initial_state) do |state, (stream_name, start_event_id)|
|
64
|
-
event_store
|
81
|
+
reader = ->(from){ read_events_from_stream(event_store, stream_name, from, count) }
|
82
|
+
read(state, start_event_id, reader)
|
65
83
|
end
|
66
84
|
end
|
67
85
|
|
86
|
+
def read_events_from_all_streams(event_store, start, count)
|
87
|
+
event_store.read_all_streams_forward(start: start, count: count)
|
88
|
+
end
|
89
|
+
|
68
90
|
def reduce_from_all_streams(event_store, start, count)
|
69
|
-
raise ArgumentError.new('Start must be valid event id or :head') unless
|
70
|
-
|
91
|
+
raise ArgumentError.new('Start must be valid event id or :head') unless valid_starting_point?(start)
|
92
|
+
reader = ->(from){ read_events_from_all_streams(event_store, from, count) }
|
93
|
+
read(initial_state, start, reader)
|
94
|
+
end
|
95
|
+
|
96
|
+
def read(initial_state, start, reader)
|
97
|
+
state = initial_state
|
98
|
+
|
99
|
+
loop do
|
100
|
+
events = reader.call(start)
|
101
|
+
break if events.empty?
|
102
|
+
|
103
|
+
reduce_events(events, state)
|
104
|
+
start = events.last.event_id
|
105
|
+
end
|
106
|
+
|
107
|
+
state
|
71
108
|
end
|
72
109
|
|
73
110
|
def start_events(start)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_event_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkency
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|