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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2cd828fa90780ea61710d291386fb028b8357653
4
- data.tar.gz: e6db6f0131ce5c157cacbdad680526fe1455438e
3
+ metadata.gz: 614b77bc975d7069bd524039c78df5291f68e0be
4
+ data.tar.gz: d975aaaa8bb77c64a74917f8e4c7d85158b5862b
5
5
  SHA512:
6
- metadata.gz: fdf4b6b333d7143de08b36948f84e3bfe9af52aecac47bd6de41470158dcdd126f5497aa2cb6707fb8382cb1836894b68914007870ffad0c37abb64d562d176e
7
- data.tar.gz: 6e3fb60f508e6a521edbad7d14414b5351b3d25a42ea34c0150af3ba268371668fb6625017a4e31cddebbf49d6bd88699f1dddbe6d4c0292dec4e0fac7a31c3e
6
+ metadata.gz: 4262004b0bb3326f3bea2d6d001dd5e1e61eeb0a202b00c9708cb9130f4ef3f8d578ba45884e5ce0e22e701fbea56affc0f781b45ec175c6dea700b75c66ccbc
7
+ data.tar.gz: c6de5b7aa1817100b9020a7980ac3e56107f18a20261b555291025f502d6e78577ef55ee2fb27e27a18be3e0311b5b033057186b7b04e45a229a8440dd4aecbd
@@ -1,3 +1,7 @@
1
+ ### 0.8.0 (21.06.2016)
2
+
3
+ * Change: Possibility to create projection based on all events PR #19
4
+
1
5
  ### 0.7.0 (21.06.2016)
2
6
 
3
7
  * Change: support for Dynamic subscriptions PR #20
@@ -1,3 +1,4 @@
1
1
  module RubyEventStore
2
2
  GLOBAL_STREAM = 'all'.freeze
3
+ PAGE_SIZE = 100.freeze
3
4
  end
@@ -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 initialize(streams)
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.reduce(initial_state) do |state, stream|
46
- event_store.read_stream_events_forward(stream).reduce(state, &method(:transition))
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
@@ -1,3 +1,3 @@
1
1
  module RubyEventStore
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.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.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rybex