ruby_event_store 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +10 -0
- data/lib/ruby_event_store/client.rb +12 -11
- data/lib/ruby_event_store/event.rb +6 -7
- data/lib/ruby_event_store/projection.rb +3 -3
- data/lib/ruby_event_store/pub_sub/broker.rb +3 -3
- data/lib/ruby_event_store/spec/event_repository_lint.rb +3 -3
- data/lib/ruby_event_store/version.rb +1 -1
- data/ruby_event_store.gemspec +8 -9
- metadata +7 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b76da76feedfe6a7a47b7580ae2ef14bb64785a7
|
4
|
+
data.tar.gz: 970d9fa6c06ad47649e1bb5f35db967d76508ba8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d952639196c9a5d24b06d985074dbcaf21c494c20c427c3e3af622f6ae096d4bbd36571f203c2eb2c7ed925aea49ea6262f445b50286eafb8ff22bb96366036
|
7
|
+
data.tar.gz: e594bb468b2ea6497c365d5c68709bc0688093331654fe3ef6b41740b331ba21225cdf13ae44c4650446a9d49ae1a2c74998adbf25b71367cccbe9989674a9ac
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
### 0.13.0 (15.10.2016)
|
2
|
+
|
3
|
+
* Change: Dropped ClosedStruct event (meta)data wrapping PR #34
|
4
|
+
Fix for Issue with ClosedStruct and object_id #33
|
5
|
+
* Change: Refactor RubyEventStore::Client to have the same methods signatures as RailsEventStore::Client (PR #35),
|
6
|
+
this will allow to remove most of the code form RailsEventStore::Client without breaking current
|
7
|
+
applications that use RailsEventStore::Client. This change is however a breaking one for RubyEventStore.
|
8
|
+
|
1
9
|
### 0.12.1 (11.08.2016)
|
2
10
|
|
3
11
|
* Fix: improve EventRepository specification tests (mutation tests)
|
data/README.md
CHANGED
@@ -16,6 +16,16 @@ All documentation and sample codes are available at [http://railseventstore.arke
|
|
16
16
|
|
17
17
|
Check the contribution guide on [CONTRIBUTING.md](https://github.com/arkency/ruby_event_store/blob/master/CONTRIBUTING.md)
|
18
18
|
|
19
|
+
We're aiming for 100% mutation coverage in this project.
|
20
|
+
Read the reasoning:
|
21
|
+
|
22
|
+
[Why I want to introduce mutation testing to the rails_event_store gem](http://blog.arkency.com/2015/04/why-i-want-to-introduce-mutation-testing-to-the-rails-event-store-gem/)
|
23
|
+
|
24
|
+
[Mutation testing and continuous integration](http://blog.arkency.com/2015/05/mutation-testing-and-continuous-integration/)
|
25
|
+
|
26
|
+
In practice, it means that we run `make mutate` as part of the CI process.
|
27
|
+
Whenever you fix a bug or add a new feature, we require that the coverage doesn't go down.
|
28
|
+
|
19
29
|
## About
|
20
30
|
|
21
31
|
<img src="http://arkency.com/images/arkency.png" alt="Arkency" width="20%" align="left" />
|
@@ -1,21 +1,22 @@
|
|
1
1
|
module RubyEventStore
|
2
2
|
class Client
|
3
|
-
def initialize(repository
|
3
|
+
def initialize(repository:,
|
4
4
|
event_broker: PubSub::Broker.new,
|
5
|
+
page_size: PAGE_SIZE,
|
5
6
|
metadata_proc: nil)
|
6
7
|
@repository = repository
|
7
8
|
@event_broker = event_broker
|
9
|
+
@page_size = page_size
|
8
10
|
@metadata_proc = metadata_proc
|
9
11
|
end
|
10
|
-
attr_reader :repository, :event_broker
|
11
12
|
|
12
13
|
def publish_event(event, stream_name: GLOBAL_STREAM, expected_version: :any)
|
13
|
-
append_to_stream(
|
14
|
+
append_to_stream(event, stream_name: stream_name, expected_version: expected_version)
|
14
15
|
event_broker.notify_subscribers(event)
|
15
16
|
:ok
|
16
17
|
end
|
17
18
|
|
18
|
-
def append_to_stream(
|
19
|
+
def append_to_stream(event, stream_name: GLOBAL_STREAM, expected_version: :any)
|
19
20
|
validate_expected_version(stream_name, expected_version)
|
20
21
|
enriched_event = enrich_event_metadata(event)
|
21
22
|
repository.create(enriched_event, stream_name)
|
@@ -28,13 +29,13 @@ module RubyEventStore
|
|
28
29
|
:ok
|
29
30
|
end
|
30
31
|
|
31
|
-
def read_events_forward(stream_name, start, count)
|
32
|
+
def read_events_forward(stream_name, start: :head, count: page_size)
|
32
33
|
raise IncorrectStreamData if stream_name.nil? || stream_name.empty?
|
33
34
|
page = Page.new(repository, start, count)
|
34
35
|
repository.read_events_forward(stream_name, page.start, page.count)
|
35
36
|
end
|
36
37
|
|
37
|
-
def read_events_backward(stream_name, start, count)
|
38
|
+
def read_events_backward(stream_name, start: :head, count: page_size)
|
38
39
|
raise IncorrectStreamData if stream_name.nil? || stream_name.empty?
|
39
40
|
page = Page.new(repository, start, count)
|
40
41
|
repository.read_events_backward(stream_name, page.start, page.count)
|
@@ -50,12 +51,12 @@ module RubyEventStore
|
|
50
51
|
repository.read_stream_events_backward(stream_name)
|
51
52
|
end
|
52
53
|
|
53
|
-
def read_all_streams_forward(start, count)
|
54
|
+
def read_all_streams_forward(start: :head, count: page_size)
|
54
55
|
page = Page.new(repository, start, count)
|
55
56
|
repository.read_all_streams_forward(page.start, page.count)
|
56
57
|
end
|
57
58
|
|
58
|
-
def read_all_streams_backward(start, count)
|
59
|
+
def read_all_streams_backward(start: :head, count: page_size)
|
59
60
|
page = Page.new(repository, start, count)
|
60
61
|
repository.read_all_streams_backward(page.start, page.count)
|
61
62
|
end
|
@@ -73,14 +74,14 @@ module RubyEventStore
|
|
73
74
|
end
|
74
75
|
|
75
76
|
private
|
76
|
-
attr_reader :metadata_proc
|
77
|
+
attr_reader :repository, :page_size, :event_broker, :metadata_proc
|
77
78
|
|
78
79
|
def enrich_event_metadata(event)
|
79
|
-
metadata = event.metadata
|
80
|
+
metadata = event.metadata
|
80
81
|
metadata[:timestamp] ||= Time.now.utc
|
81
82
|
metadata.merge!(metadata_proc.call || {}) if metadata_proc
|
82
83
|
|
83
|
-
event.class.new(event_id: event.event_id, metadata: metadata, data: event.data
|
84
|
+
event.class.new(event_id: event.event_id, metadata: metadata, data: event.data)
|
84
85
|
end
|
85
86
|
|
86
87
|
def handle_subscribe(unsub)
|
@@ -1,25 +1,24 @@
|
|
1
1
|
require 'securerandom'
|
2
|
-
require 'closed_struct'
|
3
2
|
|
4
3
|
module RubyEventStore
|
5
4
|
class Event
|
6
|
-
def initialize(event_id: SecureRandom.uuid, metadata:
|
5
|
+
def initialize(event_id: SecureRandom.uuid, metadata: nil, data: nil)
|
7
6
|
@event_id = event_id.to_s
|
8
|
-
@metadata =
|
9
|
-
@data =
|
7
|
+
@metadata = metadata.to_h
|
8
|
+
@data = data.to_h
|
10
9
|
end
|
11
10
|
attr_reader :event_id, :metadata, :data
|
12
11
|
|
13
12
|
def to_h
|
14
13
|
{
|
15
14
|
event_id: event_id,
|
16
|
-
metadata: metadata
|
17
|
-
data: data
|
15
|
+
metadata: metadata,
|
16
|
+
data: data
|
18
17
|
}
|
19
18
|
end
|
20
19
|
|
21
20
|
def timestamp
|
22
|
-
metadata
|
21
|
+
metadata[:timestamp]
|
23
22
|
end
|
24
23
|
|
25
24
|
def ==(other_event)
|
@@ -39,7 +39,7 @@ module RubyEventStore
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def call(event)
|
42
|
-
handlers
|
42
|
+
handlers.fetch(event.class).(current_state, event)
|
43
43
|
end
|
44
44
|
|
45
45
|
def handled_events
|
@@ -58,13 +58,13 @@ module RubyEventStore
|
|
58
58
|
def reduce_from_streams(event_store, start, count)
|
59
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
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))
|
61
|
+
event_store.read_events_forward(stream_name, start: start_event_id, count: count).reduce(state, &method(:transition))
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
def reduce_from_all_streams(event_store, start, count)
|
66
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))
|
67
|
+
event_store.read_all_streams_forward(start: start, count: count).reduce(initial_state, &method(:transition))
|
68
68
|
end
|
69
69
|
|
70
70
|
def start_events(start)
|
@@ -54,12 +54,12 @@ module RubyEventStore
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def subscribe(subscriber, event_types)
|
57
|
-
event_types.each{ |type| subscribers[type] << subscriber }
|
58
|
-
->() {event_types.each{ |type| subscribers
|
57
|
+
event_types.each{ |type| subscribers[type.name] << subscriber }
|
58
|
+
->() {event_types.each{ |type| subscribers.fetch(type.name).delete(subscriber) } }
|
59
59
|
end
|
60
60
|
|
61
61
|
def all_subscribers_for(event_type)
|
62
|
-
subscribers[event_type] + @global_subscribers
|
62
|
+
subscribers[event_type.name] + @global_subscribers
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
RSpec.shared_examples :event_repository do |repository_class|
|
2
2
|
TestDomainEvent = Class.new(RubyEventStore::Event)
|
3
|
-
|
3
|
+
let(:repository) { subject || repository_class.new }
|
4
4
|
|
5
5
|
it 'just created is empty' do
|
6
6
|
expect(repository.read_all_streams_forward(:head, 1)).to be_empty
|
@@ -24,14 +24,14 @@ RSpec.shared_examples :event_repository do |repository_class|
|
|
24
24
|
event = TestDomainEvent.new(data: { order_id: 3 })
|
25
25
|
repository.create(event, 'stream')
|
26
26
|
retrieved_event = repository.read_all_streams_forward(:head, 1).first
|
27
|
-
expect(retrieved_event.data
|
27
|
+
expect(retrieved_event.data[:order_id]).to eq(3)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'metadata attributes are retrieved' do
|
31
31
|
event = TestDomainEvent.new(metadata: { request_id: 3 })
|
32
32
|
repository.create(event, 'stream')
|
33
33
|
retrieved_event = repository.read_all_streams_forward(:head, 1).first
|
34
|
-
expect(retrieved_event.metadata
|
34
|
+
expect(retrieved_event.metadata[:request_id]).to eq(3)
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'does not have deleted streams' do
|
data/ruby_event_store.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'ruby_event_store/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'ruby_event_store'
|
8
8
|
spec.version = RubyEventStore::VERSION
|
9
9
|
spec.licenses = ['MIT']
|
10
10
|
spec.authors = ['Arkency']
|
@@ -15,14 +15,13 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.homepage = 'https://github.com/arkency/ruby_event_store'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
18
|
+
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency '
|
26
|
-
spec.add_development_dependency '
|
27
|
-
spec.add_development_dependency 'mutant-rspec', '~> 0.7.9'
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.8'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
25
|
+
spec.add_development_dependency 'pry', '~> 0'
|
26
|
+
spec.add_development_dependency 'mutant-rspec', '~> 0.8.11'
|
28
27
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
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.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkency
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: closed_struct
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.1'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.1'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +44,14 @@ dependencies:
|
|
58
44
|
requirements:
|
59
45
|
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
47
|
+
version: '3.4'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
54
|
+
version: '3.4'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: pry
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +72,14 @@ dependencies:
|
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
75
|
+
version: 0.8.11
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
82
|
+
version: 0.8.11
|
97
83
|
description: Implementation of Event Store in Ruby
|
98
84
|
email:
|
99
85
|
- dev@arkency.com
|
@@ -142,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
128
|
version: '0'
|
143
129
|
requirements: []
|
144
130
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
131
|
+
rubygems_version: 2.6.7
|
146
132
|
signing_key:
|
147
133
|
specification_version: 4
|
148
134
|
summary: Event Store in Ruby
|