@@ -25,7 +25,7 @@ module RubyEventStore
25
25
26
26
account_balance =
27
27
Projection
28
- . new ( 0 )
28
+ . init ( 0 )
29
29
. on ( MoneyDeposited ) { |state , event | state += event . data [ :amount ] }
30
30
. on ( MoneyWithdrawn ) { |state , event | state -= event . data [ :amount ] }
31
31
. call ( event_store . read )
@@ -40,7 +40,7 @@ module RubyEventStore
40
40
41
41
account_balance =
42
42
Projection
43
- . new ( 0 )
43
+ . init ( 0 )
44
44
. on ( MoneyDeposited ) { |state , event | state += event . data [ :amount ] }
45
45
. on ( MoneyWithdrawn ) { |state , event | state -= event . data [ :amount ] }
46
46
. call ( event_store . read )
@@ -59,7 +59,7 @@ module RubyEventStore
59
59
)
60
60
61
61
stats =
62
- Projection . new ( { } )
62
+ Projection . init ( { } )
63
63
. on ( MoneyDeposited ) { |state , event | state [ :last_deposit ] = event . data [ :amount ] ; state }
64
64
. on ( MoneyWithdrawn ) { |state , event | state [ :last_withdrawal ] = event . data [ :amount ] ; state }
65
65
. call ( event_store . read . stream ( stream_name ) )
@@ -74,7 +74,7 @@ module RubyEventStore
74
74
75
75
deposits =
76
76
Projection
77
- . new ( 0 )
77
+ . init ( 0 )
78
78
. on ( MoneyDeposited ) { |state , event | state += event . data [ :amount ] }
79
79
. call ( event_store . read . stream ( stream_name ) )
80
80
expect ( deposits ) . to eq ( 10 )
@@ -88,7 +88,7 @@ module RubyEventStore
88
88
89
89
cashflow =
90
90
Projection
91
- . new ( 0 )
91
+ . init ( 0 )
92
92
. on ( MoneyDeposited , MoneyWithdrawn ) { |state , event | state += event . data [ :amount ] }
93
93
. call ( event_store . read . stream ( stream_name ) )
94
94
expect ( cashflow ) . to eq ( 12 )
@@ -108,7 +108,7 @@ module RubyEventStore
108
108
109
109
balance =
110
110
Projection
111
- . new ( 0 )
111
+ . init ( 0 )
112
112
. on ( MoneyDeposited ) { |state , event | state += event . data [ :amount ] }
113
113
. on ( MoneyWithdrawn ) { |state , event | state -= event . data [ :amount ] }
114
114
. call ( event_store . read . stream ( stream_name ) . in_batches ( 2 ) )
@@ -129,7 +129,7 @@ module RubyEventStore
129
129
130
130
balance =
131
131
Projection
132
- . new ( 0 )
132
+ . init ( 0 )
133
133
. on ( MoneyDeposited ) { |state , event | state += event . data [ :amount ] }
134
134
. on ( MoneyWithdrawn ) { |state , event | state -= event . data [ :amount ] }
135
135
. call ( event_store . read . stream ( stream_name ) . from ( starting . event_id ) . in_batches ( 2 ) )
@@ -145,7 +145,7 @@ module RubyEventStore
145
145
146
146
balance =
147
147
Projection
148
- . new ( 0 )
148
+ . init ( 0 )
149
149
. on ( MoneyDeposited ) { |state , event | state += event . data [ :amount ] }
150
150
. on ( MoneyWithdrawn ) { |state , event | state -= event . data [ :amount ] }
151
151
. call ( event_store . read . in_batches ( 2 ) )
@@ -161,7 +161,7 @@ module RubyEventStore
161
161
162
162
balance =
163
163
Projection
164
- . new ( 0 )
164
+ . init ( 0 )
165
165
. on ( MoneyDeposited ) { |state , event | state += event . data [ :amount ] }
166
166
. on ( MoneyWithdrawn ) { |state , event | state -= event . data [ :amount ] }
167
167
. call ( event_store . read . from ( starting . event_id ) . in_batches ( 2 ) )
@@ -185,7 +185,7 @@ module RubyEventStore
185
185
186
186
balance =
187
187
Projection
188
- . new ( 0 )
188
+ . init ( 0 )
189
189
. on ( MoneyDeposited ) { |state , event | state += event . data [ :amount ] }
190
190
. on ( MoneyWithdrawn , MoneyLost ) { |state , event | state -= event . data [ :amount ] }
191
191
. call ( event_store . read . in_batches ( 100 ) )
@@ -198,39 +198,39 @@ module RubyEventStore
198
198
expect ( repository ) . to receive ( :read ) . with ( scope . result ) . and_return ( [ ] )
199
199
200
200
Projection
201
- . new ( 0 )
201
+ . init ( 0 )
202
202
. on ( MoneyDeposited ) { |state , event | state += event . data [ :amount ] }
203
203
. on ( MoneyWithdrawn ) { |state , event | state -= event . data [ :amount ] }
204
204
. call ( scope )
205
205
end
206
206
207
207
specify "default initial state" do
208
- expect ( Projection . new . call ( [ ] ) ) . to eq ( nil )
208
+ expect ( Projection . init . call ( [ ] ) ) . to eq ( nil )
209
209
end
210
210
211
211
specify "block must be given to on event handlers" do
212
212
expect do
213
- Projection . new . on ( MoneyDeposited )
213
+ Projection . init . on ( MoneyDeposited )
214
214
end . to raise_error ( ArgumentError , "No handler block given" )
215
215
end
216
216
217
217
it "does not support anonymous events" do
218
218
expect do
219
- Projection . new . on ( Class . new ) { |_state , _event | }
219
+ Projection . init . on ( Class . new ) { |_state , _event | }
220
220
end . to raise_error ( ArgumentError , "Anonymous class is missing name" )
221
221
end
222
222
223
223
specify do
224
224
expect ( repository ) . not_to receive ( :read )
225
- state = Projection . new . call ( event_store . read )
225
+ state = Projection . init . call ( event_store . read )
226
226
expect ( state ) . to eq ( nil )
227
227
end
228
228
229
229
specify do
230
230
expect ( repository ) . not_to receive ( :read )
231
231
232
232
initial_state = Object . new
233
- state = Projection . new ( initial_state ) . call ( event_store . read )
233
+ state = Projection . init ( initial_state ) . call ( event_store . read )
234
234
235
235
expect ( state ) . to eq ( initial_state )
236
236
end
0 commit comments