ruby_event_store 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/CHANGELOG.md +5 -0
- data/Makefile +1 -1
- data/README.md +16 -1
- data/lib/ruby_event_store.rb +2 -0
- data/lib/ruby_event_store/client.rb +5 -3
- data/lib/ruby_event_store/deprecations.rb +7 -0
- data/lib/ruby_event_store/errors.rb +6 -1
- data/lib/ruby_event_store/pub_sub/broker.rb +0 -19
- data/lib/ruby_event_store/pub_sub/dispatcher.rb +10 -0
- data/lib/ruby_event_store/spec/dispatcher_lint.rb +17 -0
- data/lib/ruby_event_store/spec/event_broker_lint.rb +2 -2
- data/lib/ruby_event_store/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d71ec6a5d4c85e551b036dda5abca24e8bddc1c
|
4
|
+
data.tar.gz: 65666ce24c97b6818a2881a8ce543c4571b88192
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf14a4789d7f4194598b39a8a09ad91f3baca78f6976792499a02476186b76c40a1059e12f926254e1075acc34da7b7a2f1147bea7d8a8f069f9c97e897146ba
|
7
|
+
data.tar.gz: f3014bb612918f1e39a68d719705faf4a9a6227c901883978ea5414135f2fc47c30e33afebaab07b7e718a0394bb5cdeeda3d6165b94d0679aebead526c9ceac
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Makefile
CHANGED
@@ -10,7 +10,7 @@ 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 --ignore-subject "RubyEventStore.const_missing" "RubyEventStore*"
|
14
14
|
|
15
15
|
.PHONY: help
|
16
16
|
|
data/README.md
CHANGED
@@ -28,8 +28,23 @@ Whenever you fix a bug or add a new feature, we require that the coverage doesn'
|
|
28
28
|
|
29
29
|
## About
|
30
30
|
|
31
|
-
<img src="http://arkency.com/images/arkency.png" alt="Arkency" width="
|
31
|
+
<img src="http://arkency.com/images/arkency.png" alt="Arkency" width="60px" align="left" />
|
32
32
|
|
33
33
|
This repository is funded and maintained by Arkency. Check out our other [open-source projects](https://github.com/arkency).
|
34
34
|
|
35
35
|
You can also [hire us](http://arkency.com) or [read our blog](http://blog.arkency.com).
|
36
|
+
|
37
|
+
|
38
|
+
## Learn more about DDD & Event Sourcing
|
39
|
+
|
40
|
+
Check our **Rails + Domain Driven Design Workshop** [more details](http://blog.arkency.com/ddd-training/).
|
41
|
+
|
42
|
+
Why You should attend? Robert has explained this in [this blogpost](http://blog.arkency.com/2016/12/why-would-you-even-want-to-listen-about-ddd/).
|
43
|
+
|
44
|
+
|
45
|
+
Next edition will be held on **21-22th September 2017** in Berlin, Germany.
|
46
|
+
Another edition is also planned for November in London.
|
47
|
+
|
48
|
+
You may also consider buying the [Domain-Driven Rails book](http://blog.arkency.com/domain-driven-rails/).
|
49
|
+
Workshop will be held in English.
|
50
|
+
|
data/lib/ruby_event_store.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'ruby_event_store/pub_sub/dispatcher'
|
1
2
|
require 'ruby_event_store/pub_sub/broker'
|
2
3
|
require 'ruby_event_store/in_memory_repository'
|
3
4
|
require 'ruby_event_store/projection'
|
@@ -5,4 +6,5 @@ require 'ruby_event_store/errors'
|
|
5
6
|
require 'ruby_event_store/constants'
|
6
7
|
require 'ruby_event_store/client'
|
7
8
|
require 'ruby_event_store/event'
|
9
|
+
require 'ruby_event_store/deprecations'
|
8
10
|
require 'ruby_event_store/version'
|
@@ -3,11 +3,13 @@ module RubyEventStore
|
|
3
3
|
def initialize(repository:,
|
4
4
|
event_broker: PubSub::Broker.new,
|
5
5
|
page_size: PAGE_SIZE,
|
6
|
-
metadata_proc: nil
|
6
|
+
metadata_proc: nil,
|
7
|
+
clock: ->{ Time.now.utc })
|
7
8
|
@repository = repository
|
8
9
|
@event_broker = event_broker
|
9
10
|
@page_size = page_size
|
10
11
|
@metadata_proc = metadata_proc
|
12
|
+
@clock = clock
|
11
13
|
end
|
12
14
|
|
13
15
|
def publish_event(event, stream_name: GLOBAL_STREAM, expected_version: :any)
|
@@ -74,11 +76,11 @@ module RubyEventStore
|
|
74
76
|
end
|
75
77
|
|
76
78
|
private
|
77
|
-
attr_reader :repository, :page_size, :event_broker, :metadata_proc
|
79
|
+
attr_reader :repository, :page_size, :event_broker, :metadata_proc, :clock
|
78
80
|
|
79
81
|
def enrich_event_metadata(event)
|
80
82
|
metadata = event.metadata
|
81
|
-
metadata[:timestamp] ||=
|
83
|
+
metadata[:timestamp] ||= clock.()
|
82
84
|
metadata.merge!(metadata_proc.call || {}) if metadata_proc
|
83
85
|
|
84
86
|
event.class.new(event_id: event.event_id, metadata: metadata, data: event.data)
|
@@ -4,7 +4,12 @@ module RubyEventStore
|
|
4
4
|
IncorrectStreamData = Class.new(StandardError)
|
5
5
|
EventNotFound = Class.new(StandardError)
|
6
6
|
SubscriberNotExist = Class.new(StandardError)
|
7
|
-
MethodNotDefined = Class.new(StandardError)
|
8
7
|
InvalidPageStart = Class.new(ArgumentError)
|
9
8
|
InvalidPageSize = Class.new(ArgumentError)
|
9
|
+
|
10
|
+
class InvalidHandler < StandardError
|
11
|
+
def initialize(subscriber)
|
12
|
+
super("#call method not found in #{subscriber.class} subscriber. Are you sure it is a valid subscriber?")
|
13
|
+
end
|
14
|
+
end
|
10
15
|
end
|
@@ -1,25 +1,6 @@
|
|
1
1
|
module RubyEventStore
|
2
2
|
module PubSub
|
3
3
|
class Broker
|
4
|
-
class Dispatcher
|
5
|
-
def call(subscriber, event)
|
6
|
-
ensure_method_defined(subscriber)
|
7
|
-
subscriber.call(event)
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
def ensure_method_defined(subscriber)
|
12
|
-
unless subscriber.respond_to?(:call)
|
13
|
-
raise MethodNotDefined.new(method_not_defined_message(subscriber))
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def method_not_defined_message(subscriber)
|
18
|
-
"#call method not found in #{subscriber.class} subscriber. Are you sure it is a valid subscriber?"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
private_constant :Dispatcher
|
22
|
-
|
23
4
|
DEFAULT_DISPATCHER = Dispatcher.new
|
24
5
|
|
25
6
|
def initialize(dispatcher: DEFAULT_DISPATCHER)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
RSpec.shared_examples :dispatcher do |dispatcher|
|
2
|
+
specify "calls subscribed handler" do
|
3
|
+
handler = double(:handler)
|
4
|
+
event = instance_double(::RubyEventStore::Event)
|
5
|
+
|
6
|
+
expect(handler).to receive(:call).with(event)
|
7
|
+
dispatcher.(handler, event)
|
8
|
+
end
|
9
|
+
|
10
|
+
specify "error when invalid subscriber passed" do
|
11
|
+
handler = double(:handler)
|
12
|
+
event = instance_double(::RubyEventStore::Event)
|
13
|
+
|
14
|
+
expect { dispatcher.(handler, event) }.to raise_error(::RubyEventStore::InvalidHandler,
|
15
|
+
"#call method not found in RSpec::Mocks::Double subscriber. Are you sure it is a valid subscriber?")
|
16
|
+
end
|
17
|
+
end
|
@@ -63,7 +63,7 @@ RSpec.shared_examples :event_broker do |broker_class|
|
|
63
63
|
" Are you sure it is a valid subscriber?"
|
64
64
|
subscriber = InvalidTestHandler.new
|
65
65
|
broker.add_subscriber(subscriber, [Test1DomainEvent])
|
66
|
-
expect { broker.notify_subscribers(Test1DomainEvent.new) }.to raise_error(RubyEventStore::
|
66
|
+
expect { broker.notify_subscribers(Test1DomainEvent.new) }.to raise_error(RubyEventStore::InvalidHandler, message)
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'raises error when no valid method on global handler' do
|
@@ -72,7 +72,7 @@ RSpec.shared_examples :event_broker do |broker_class|
|
|
72
72
|
" Are you sure it is a valid subscriber?"
|
73
73
|
subscriber = InvalidTestHandler.new
|
74
74
|
broker.add_global_subscriber(subscriber)
|
75
|
-
expect { broker.notify_subscribers(Test1DomainEvent.new) }.to raise_error(RubyEventStore::
|
75
|
+
expect { broker.notify_subscribers(Test1DomainEvent.new) }.to raise_error(RubyEventStore::InvalidHandler, message)
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'returns lambda as an output of global subscribe methods' do
|
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.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkency
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,11 +99,14 @@ files:
|
|
99
99
|
- lib/ruby_event_store.rb
|
100
100
|
- lib/ruby_event_store/client.rb
|
101
101
|
- lib/ruby_event_store/constants.rb
|
102
|
+
- lib/ruby_event_store/deprecations.rb
|
102
103
|
- lib/ruby_event_store/errors.rb
|
103
104
|
- lib/ruby_event_store/event.rb
|
104
105
|
- lib/ruby_event_store/in_memory_repository.rb
|
105
106
|
- lib/ruby_event_store/projection.rb
|
106
107
|
- lib/ruby_event_store/pub_sub/broker.rb
|
108
|
+
- lib/ruby_event_store/pub_sub/dispatcher.rb
|
109
|
+
- lib/ruby_event_store/spec/dispatcher_lint.rb
|
107
110
|
- lib/ruby_event_store/spec/event_broker_lint.rb
|
108
111
|
- lib/ruby_event_store/spec/event_repository_lint.rb
|
109
112
|
- lib/ruby_event_store/version.rb
|
@@ -128,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
131
|
version: '0'
|
129
132
|
requirements: []
|
130
133
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.6.
|
134
|
+
rubygems_version: 2.6.11
|
132
135
|
signing_key:
|
133
136
|
specification_version: 4
|
134
137
|
summary: Event Store in Ruby
|