ruby_event_store 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE +22 -0
- data/lib/ruby_event_store/projection.rb +2 -2
- data/lib/ruby_event_store/pub_sub/broker.rb +25 -12
- data/lib/ruby_event_store/spec/event_broker_lint.rb +56 -7
- data/lib/ruby_event_store/version.rb +1 -1
- data/ruby_event_store.gemspec +3 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccc76d1623b794eed62f855d2e8639cfb1e8448a
|
4
|
+
data.tar.gz: d23636b51426bfc1318b5b3b2fa6f66f7a11bd88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdc4e73526e305ee7009f18a49a867d9c3c94dc26ce8c9a50b4449443a99339742f72404764e1b35ef274b4b7aed5d875987658a6a5ce2107446fbf251ba9956
|
7
|
+
data.tar.gz: 0c23c71f915e4666c8e3f2fa5ebd82ed92e2010295ff824c3b7d53d49a61b56d36e50f0f9346754cf96417bd75e2a811c6b39e1e7a291a03dd686f911d4f6d6d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
### 0.9.0 (24.06.2016)
|
2
|
+
|
3
|
+
* Change: Call instead of handle_event, handle_event stays for now but is deprecated PR #18
|
4
|
+
* Fix: Clarify Licensing terms #23 - MIT licence it is from now
|
5
|
+
|
1
6
|
### 0.8.0 (21.06.2016)
|
2
7
|
|
3
8
|
* Change: Possibility to create projection based on all events PR #19
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Arkency
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
@@ -38,7 +38,7 @@ module RubyEventStore
|
|
38
38
|
@current_state ||= initial_state
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
41
|
+
def call(event)
|
42
42
|
handlers[event.class].(current_state, event)
|
43
43
|
end
|
44
44
|
|
@@ -46,7 +46,7 @@ module RubyEventStore
|
|
46
46
|
handlers.keys
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
49
|
+
def run(event_store, start = :head, count = PAGE_SIZE)
|
50
50
|
if streams.any?
|
51
51
|
reduce_from_streams(event_store, start, count)
|
52
52
|
else
|
@@ -1,7 +1,31 @@
|
|
1
1
|
module RubyEventStore
|
2
2
|
module PubSub
|
3
3
|
class Broker
|
4
|
-
|
4
|
+
class Dispatcher
|
5
|
+
def call(subscriber, event)
|
6
|
+
ensure_method_defined(subscriber)
|
7
|
+
if subscriber.respond_to?(:call)
|
8
|
+
subscriber.call(event)
|
9
|
+
else
|
10
|
+
warn "[DEPRECATION] `handle_event` is deprecated. Please use `call` instead."
|
11
|
+
subscriber.handle_event(event)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def ensure_method_defined(subscriber)
|
17
|
+
unless subscriber.respond_to?(:call) || subscriber.respond_to?(:handle_event)
|
18
|
+
raise MethodNotDefined.new(method_not_defined_message(subscriber))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_not_defined_message(subscriber)
|
23
|
+
"Neither #call nor #handle_event method found in #{subscriber.class} subscriber. Are you sure it is a valid subscriber?"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
private_constant :Dispatcher
|
27
|
+
|
28
|
+
DEFAULT_DISPATCHER = Dispatcher.new
|
5
29
|
|
6
30
|
def initialize(dispatcher = DEFAULT_DISPATCHER)
|
7
31
|
@subscribers = Hash.new {|hsh, key| hsh[key] = [] }
|
@@ -32,7 +56,6 @@ module RubyEventStore
|
|
32
56
|
|
33
57
|
def verify_subscriber(subscriber)
|
34
58
|
raise SubscriberNotExist if subscriber.nil?
|
35
|
-
ensure_method_defined(subscriber)
|
36
59
|
end
|
37
60
|
|
38
61
|
def subscribe(subscriber, event_types)
|
@@ -40,19 +63,9 @@ module RubyEventStore
|
|
40
63
|
->() {event_types.each{ |type| subscribers[type].delete(subscriber) } }
|
41
64
|
end
|
42
65
|
|
43
|
-
def ensure_method_defined(subscriber)
|
44
|
-
unless subscriber.methods.include? :handle_event
|
45
|
-
raise MethodNotDefined.new(method_not_defined_message(subscriber))
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
66
|
def all_subscribers_for(event_type)
|
50
67
|
subscribers[event_type] + @global_subscribers
|
51
68
|
end
|
52
|
-
|
53
|
-
def method_not_defined_message(subscriber)
|
54
|
-
"#handle_event method is not found in #{subscriber.class} subscriber. Are you sure it is a valid subscriber?"
|
55
|
-
end
|
56
69
|
end
|
57
70
|
end
|
58
71
|
end
|
@@ -3,9 +3,9 @@ RSpec.shared_examples :event_broker do |broker_class|
|
|
3
3
|
Test2DomainEvent = Class.new(RubyEventStore::Event)
|
4
4
|
Test3DomainEvent = Class.new(RubyEventStore::Event)
|
5
5
|
|
6
|
-
class
|
6
|
+
class InvalidTestHandler
|
7
7
|
end
|
8
|
-
class
|
8
|
+
class DeprectatedTestHandler
|
9
9
|
def initialize
|
10
10
|
@events = []
|
11
11
|
end
|
@@ -16,6 +16,17 @@ RSpec.shared_examples :event_broker do |broker_class|
|
|
16
16
|
|
17
17
|
attr_reader :events
|
18
18
|
end
|
19
|
+
class TestHandler
|
20
|
+
def initialize
|
21
|
+
@events = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(event)
|
25
|
+
@events << event
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_reader :events
|
29
|
+
end
|
19
30
|
class TestDispatcher
|
20
31
|
attr_reader :dispatched
|
21
32
|
|
@@ -57,13 +68,44 @@ RSpec.shared_examples :event_broker do |broker_class|
|
|
57
68
|
expect(global_handler.events).to eq([event1,event2,event3])
|
58
69
|
end
|
59
70
|
|
71
|
+
it 'notify subscribed deprecated handlers' do
|
72
|
+
handler = DeprectatedTestHandler.new
|
73
|
+
another_handler = DeprectatedTestHandler.new
|
74
|
+
global_handler = DeprectatedTestHandler.new
|
75
|
+
|
76
|
+
broker.add_subscriber(handler, [Test1DomainEvent, Test3DomainEvent])
|
77
|
+
broker.add_subscriber(another_handler, [Test2DomainEvent])
|
78
|
+
broker.add_global_subscriber(global_handler)
|
79
|
+
|
80
|
+
event1 = Test1DomainEvent.new
|
81
|
+
event2 = Test2DomainEvent.new
|
82
|
+
event3 = Test3DomainEvent.new
|
83
|
+
|
84
|
+
[event1, event2, event3].each do |ev|
|
85
|
+
broker.notify_subscribers(ev)
|
86
|
+
end
|
87
|
+
|
88
|
+
expect(handler.events).to eq([event1,event3])
|
89
|
+
expect(another_handler.events).to eq([event2])
|
90
|
+
expect(global_handler.events).to eq([event1,event2,event3])
|
91
|
+
end
|
92
|
+
|
60
93
|
it 'raises error when no valid method on handler' do
|
61
|
-
message = "#handle_event method
|
62
|
-
"in
|
94
|
+
message = "Neither #call nor #handle_event method found " +
|
95
|
+
"in InvalidTestHandler subscriber." +
|
96
|
+
" Are you sure it is a valid subscriber?"
|
97
|
+
subscriber = InvalidTestHandler.new
|
98
|
+
broker.add_subscriber(subscriber, [Test1DomainEvent])
|
99
|
+
expect { broker.notify_subscribers(Test1DomainEvent.new) }.to raise_error(RubyEventStore::MethodNotDefined, message)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'raises error when no valid method on global handler' do
|
103
|
+
message = "Neither #call nor #handle_event method found " +
|
104
|
+
"in InvalidTestHandler subscriber." +
|
63
105
|
" Are you sure it is a valid subscriber?"
|
64
|
-
subscriber =
|
65
|
-
|
66
|
-
expect { broker.
|
106
|
+
subscriber = InvalidTestHandler.new
|
107
|
+
broker.add_global_subscriber(subscriber)
|
108
|
+
expect { broker.notify_subscribers(Test1DomainEvent.new) }.to raise_error(RubyEventStore::MethodNotDefined, message)
|
67
109
|
end
|
68
110
|
|
69
111
|
it 'returns lambda as an output of global subscribe methods' do
|
@@ -114,4 +156,11 @@ RSpec.shared_examples :event_broker do |broker_class|
|
|
114
156
|
expect(dispatcher.dispatched).to eq([{subscriber: handler, event: event1}])
|
115
157
|
end
|
116
158
|
|
159
|
+
it 'deprecation message when no call method in handler' do
|
160
|
+
subscriber = DeprectatedTestHandler.new
|
161
|
+
broker.add_global_subscriber(subscriber)
|
162
|
+
expect { broker.notify_subscribers(Test1DomainEvent.new) }.to output(
|
163
|
+
"[DEPRECATION] `handle_event` is deprecated. Please use `call` instead.\n").to_stderr
|
164
|
+
end
|
165
|
+
|
117
166
|
end
|
data/ruby_event_store.gemspec
CHANGED
@@ -6,8 +6,9 @@ require 'ruby_event_store/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "ruby_event_store"
|
8
8
|
spec.version = RubyEventStore::VERSION
|
9
|
-
spec.
|
10
|
-
spec.
|
9
|
+
spec.licenses = ['MIT']
|
10
|
+
spec.authors = ['Arkency']
|
11
|
+
spec.email = ['dev@arkency.com']
|
11
12
|
|
12
13
|
spec.summary = %q{Event Store in Ruby}
|
13
14
|
spec.description = %q{Implementation of Event Store in Ruby}
|
metadata
CHANGED
@@ -1,15 +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.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
- mpraglowski
|
7
|
+
- Arkency
|
9
8
|
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
@@ -83,8 +82,7 @@ dependencies:
|
|
83
82
|
version: 0.7.9
|
84
83
|
description: Implementation of Event Store in Ruby
|
85
84
|
email:
|
86
|
-
-
|
87
|
-
- m@praglowski.com
|
85
|
+
- dev@arkency.com
|
88
86
|
executables: []
|
89
87
|
extensions: []
|
90
88
|
extra_rdoc_files: []
|
@@ -94,6 +92,7 @@ files:
|
|
94
92
|
- CHANGELOG.md
|
95
93
|
- CONTRIBUTING.md
|
96
94
|
- Gemfile
|
95
|
+
- LICENSE
|
97
96
|
- Makefile
|
98
97
|
- README.md
|
99
98
|
- Rakefile
|
@@ -110,7 +109,8 @@ files:
|
|
110
109
|
- lib/ruby_event_store/version.rb
|
111
110
|
- ruby_event_store.gemspec
|
112
111
|
homepage: https://github.com/arkency/ruby_event_store
|
113
|
-
licenses:
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
114
|
metadata: {}
|
115
115
|
post_install_message:
|
116
116
|
rdoc_options: []
|