ruby_event_store 0.24.0 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Makefile +29 -18
- data/lib/ruby_event_store/client.rb +24 -25
- data/lib/ruby_event_store/in_memory_repository.rb +10 -11
- data/lib/ruby_event_store/mappers/default.rb +5 -9
- data/lib/ruby_event_store/pub_sub/broker.rb +5 -6
- data/lib/ruby_event_store/spec/event_repository_lint.rb +2 -1
- data/lib/ruby_event_store/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 117724693784e5bf80bf4692eca63f78acf071bd7542ff4c45b1e588a267715e
|
4
|
+
data.tar.gz: ced1b8255f9994c47e8db8ad7442ee0a5b181720f37a1681130110f8480b1961
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9310f649919f14d1d6b6a33b71f29103eacfb958c2c5c37902529a2154698c2292c5cb4342c38238352abfe7368479347a754a2b67f9788c637ec3188e515e40
|
7
|
+
data.tar.gz: 706c18cba2de9614d3dce903e64bdcafdeaa4efb17cb9b0129df7914f336a204c29ceb06d115e25de4ede0264424bb4e3d918f900ba894c4d77b0905a103d752
|
data/Makefile
CHANGED
@@ -1,32 +1,43 @@
|
|
1
|
-
GEM_VERSION
|
1
|
+
GEM_VERSION = $(shell cat ../RES_VERSION)
|
2
|
+
GEM_NAME = ruby_event_store
|
3
|
+
REQUIRE = $(GEM_NAME)
|
4
|
+
IGNORE = RubyEventStore.const_missing \
|
5
|
+
RubyEventStore::InMemoryRepository\#append_with_synchronize \
|
6
|
+
RubyEventStore::InMemoryRepository\#normalize_to_array \
|
7
|
+
RubyEventStore::Client\#normalize_to_array \
|
8
|
+
RubyEventStore::SerializedRecord \
|
9
|
+
RubyEventStore::Projection\#read_events_from_stream \
|
10
|
+
RubyEventStore::Projection\#read_events_from_all_streams
|
11
|
+
SUBJECT ?= RubyEventStore*
|
2
12
|
|
3
13
|
install: ## Install gem dependencies
|
4
14
|
@echo "Installing gem dependencies"
|
5
15
|
@bundle install
|
6
16
|
|
7
|
-
test: ## Run tests
|
8
|
-
@echo "Running
|
17
|
+
test: ## Run unit tests
|
18
|
+
@echo "Running unit tests"
|
9
19
|
@bundle exec rspec
|
10
20
|
|
11
|
-
mutate: test
|
12
|
-
@echo "Running mutation tests
|
13
|
-
@bundle exec mutant --include lib
|
14
|
-
--
|
15
|
-
--ignore-subject
|
16
|
-
--
|
17
|
-
--ignore-subject "RubyEventStore::Client#normalize_to_array" \
|
18
|
-
--ignore-subject "RubyEventStore::SerializedRecord" \
|
19
|
-
--ignore-subject "RubyEventStore::Projection#read_events_from_stream" \
|
20
|
-
--ignore-subject "RubyEventStore::Projection#read_events_from_all_streams"
|
21
|
-
|
21
|
+
mutate: test ## Run mutation tests
|
22
|
+
@echo "Running mutation tests"
|
23
|
+
@bundle exec mutant --include lib \
|
24
|
+
$(addprefix --require ,$(REQUIRE)) \
|
25
|
+
$(addprefix --ignore-subject ,$(IGNORE)) \
|
26
|
+
--use rspec "$(SUBJECT)"
|
22
27
|
|
23
28
|
build:
|
24
|
-
@
|
29
|
+
@echo "Building gem package"
|
30
|
+
@gem build -V $(GEM_NAME).gemspec
|
25
31
|
@mkdir -p pkg/
|
26
|
-
@mv
|
32
|
+
@mv $(GEM_NAME)-$(GEM_VERSION).gem pkg/
|
33
|
+
|
34
|
+
push:
|
35
|
+
@echo "Pushing package to RubyGems"
|
36
|
+
@gem push pkg/$(GEM_NAME)-$(GEM_VERSION).gem
|
27
37
|
|
28
|
-
|
29
|
-
@
|
38
|
+
clean:
|
39
|
+
@echo "Removing previously built package"
|
40
|
+
-rm pkg/$(GEM_NAME)-$(GEM_VERSION).gem
|
30
41
|
|
31
42
|
help:
|
32
43
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
@@ -15,7 +15,7 @@ module RubyEventStore
|
|
15
15
|
def publish_events(events, stream_name: GLOBAL_STREAM, expected_version: :any)
|
16
16
|
append_to_stream(events, stream_name: stream_name, expected_version: expected_version)
|
17
17
|
events.each do |ev|
|
18
|
-
event_broker.notify_subscribers(ev)
|
18
|
+
@event_broker.notify_subscribers(ev)
|
19
19
|
end
|
20
20
|
:ok
|
21
21
|
end
|
@@ -27,75 +27,74 @@ module RubyEventStore
|
|
27
27
|
def append_to_stream(events, stream_name: GLOBAL_STREAM, expected_version: :any)
|
28
28
|
events = normalize_to_array(events)
|
29
29
|
events.each{|event| enrich_event_metadata(event) }
|
30
|
-
repository.append_to_stream(events, stream_name, expected_version)
|
30
|
+
@repository.append_to_stream(events, stream_name, expected_version)
|
31
31
|
:ok
|
32
32
|
end
|
33
33
|
|
34
34
|
def link_to_stream(event_ids, stream_name:, expected_version: :any)
|
35
|
-
repository.link_to_stream(event_ids, stream_name, expected_version)
|
35
|
+
@repository.link_to_stream(event_ids, stream_name, expected_version)
|
36
36
|
self
|
37
37
|
end
|
38
38
|
|
39
39
|
def delete_stream(stream_name)
|
40
40
|
raise IncorrectStreamData if stream_name.nil? || stream_name.empty?
|
41
|
-
repository.delete_stream(stream_name)
|
41
|
+
@repository.delete_stream(stream_name)
|
42
42
|
:ok
|
43
43
|
end
|
44
44
|
|
45
|
-
def read_events_forward(stream_name, start: :head, count: page_size)
|
45
|
+
def read_events_forward(stream_name, start: :head, count: @page_size)
|
46
46
|
raise IncorrectStreamData if stream_name.nil? || stream_name.empty?
|
47
|
-
page = Page.new(repository, start, count)
|
48
|
-
repository.read_events_forward(stream_name, page.start, page.count)
|
47
|
+
page = Page.new(@repository, start, count)
|
48
|
+
@repository.read_events_forward(stream_name, page.start, page.count)
|
49
49
|
end
|
50
50
|
|
51
|
-
def read_events_backward(stream_name, start: :head, count: page_size)
|
51
|
+
def read_events_backward(stream_name, start: :head, count: @page_size)
|
52
52
|
raise IncorrectStreamData if stream_name.nil? || stream_name.empty?
|
53
|
-
page = Page.new(repository, start, count)
|
54
|
-
repository.read_events_backward(stream_name, page.start, page.count)
|
53
|
+
page = Page.new(@repository, start, count)
|
54
|
+
@repository.read_events_backward(stream_name, page.start, page.count)
|
55
55
|
end
|
56
56
|
|
57
57
|
def read_stream_events_forward(stream_name)
|
58
58
|
raise IncorrectStreamData if stream_name.nil? || stream_name.empty?
|
59
|
-
repository.read_stream_events_forward(stream_name)
|
59
|
+
@repository.read_stream_events_forward(stream_name)
|
60
60
|
end
|
61
61
|
|
62
62
|
def read_stream_events_backward(stream_name)
|
63
63
|
raise IncorrectStreamData if stream_name.nil? || stream_name.empty?
|
64
|
-
repository.read_stream_events_backward(stream_name)
|
64
|
+
@repository.read_stream_events_backward(stream_name)
|
65
65
|
end
|
66
66
|
|
67
|
-
def read_all_streams_forward(start: :head, count: page_size)
|
68
|
-
page = Page.new(repository, start, count)
|
69
|
-
repository.read_all_streams_forward(page.start, page.count)
|
67
|
+
def read_all_streams_forward(start: :head, count: @page_size)
|
68
|
+
page = Page.new(@repository, start, count)
|
69
|
+
@repository.read_all_streams_forward(page.start, page.count)
|
70
70
|
end
|
71
71
|
|
72
|
-
def read_all_streams_backward(start: :head, count: page_size)
|
73
|
-
page = Page.new(repository, start, count)
|
74
|
-
repository.read_all_streams_backward(page.start, page.count)
|
72
|
+
def read_all_streams_backward(start: :head, count: @page_size)
|
73
|
+
page = Page.new(@repository, start, count)
|
74
|
+
@repository.read_all_streams_backward(page.start, page.count)
|
75
75
|
end
|
76
76
|
|
77
77
|
def read_event(event_id)
|
78
|
-
repository.read_event(event_id)
|
78
|
+
@repository.read_event(event_id)
|
79
79
|
end
|
80
80
|
|
81
81
|
def get_all_streams
|
82
|
-
repository.get_all_streams
|
82
|
+
@repository.get_all_streams
|
83
83
|
end
|
84
84
|
|
85
85
|
def subscribe(subscriber, event_types, &proc)
|
86
|
-
event_broker.add_subscriber(subscriber, event_types).tap do |unsub|
|
86
|
+
@event_broker.add_subscriber(subscriber, event_types).tap do |unsub|
|
87
87
|
handle_subscribe(unsub, &proc)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
def subscribe_to_all_events(subscriber, &proc)
|
92
|
-
event_broker.add_global_subscriber(subscriber).tap do |unsub|
|
92
|
+
@event_broker.add_global_subscriber(subscriber).tap do |unsub|
|
93
93
|
handle_subscribe(unsub, &proc)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
private
|
98
|
-
attr_reader :repository, :page_size, :event_broker, :metadata_proc, :clock
|
99
98
|
|
100
99
|
def normalize_to_array(events)
|
101
100
|
return *events
|
@@ -103,8 +102,8 @@ module RubyEventStore
|
|
103
102
|
|
104
103
|
def enrich_event_metadata(event)
|
105
104
|
metadata = event.metadata
|
106
|
-
metadata[:timestamp] ||= clock.()
|
107
|
-
metadata.merge!(metadata_proc.call || {}) if metadata_proc
|
105
|
+
metadata[:timestamp] ||= @clock.()
|
106
|
+
metadata.merge!(@metadata_proc.call || {}) if @metadata_proc
|
108
107
|
|
109
108
|
# event.class.new(event_id: event.event_id, metadata: metadata, data: event.data)
|
110
109
|
end
|
@@ -19,11 +19,11 @@ module RubyEventStore
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def delete_stream(stream_name)
|
22
|
-
streams.delete(stream_name)
|
22
|
+
@streams.delete(stream_name)
|
23
23
|
end
|
24
24
|
|
25
25
|
def has_event?(event_id)
|
26
|
-
all.any?{ |item| item.event_id.eql?(event_id) }
|
26
|
+
@all.any?{ |item| item.event_id.eql?(event_id) }
|
27
27
|
end
|
28
28
|
|
29
29
|
def last_stream_event(stream_name)
|
@@ -41,7 +41,7 @@ module RubyEventStore
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def read_stream_events_forward(stream_name)
|
44
|
-
streams[stream_name] || Array.new
|
44
|
+
@streams[stream_name] || Array.new
|
45
45
|
end
|
46
46
|
|
47
47
|
def read_stream_events_backward(stream_name)
|
@@ -49,23 +49,22 @@ module RubyEventStore
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def read_all_streams_forward(start_event_id, count)
|
52
|
-
read_batch(all, start_event_id, count)
|
52
|
+
read_batch(@all, start_event_id, count)
|
53
53
|
end
|
54
54
|
|
55
55
|
def read_all_streams_backward(start_event_id, count)
|
56
|
-
read_batch(all.reverse, start_event_id, count)
|
56
|
+
read_batch(@all.reverse, start_event_id, count)
|
57
57
|
end
|
58
58
|
|
59
59
|
def read_event(event_id)
|
60
|
-
all.find { |e| event_id.eql?(e.event_id) } or raise EventNotFound.new(event_id)
|
60
|
+
@all.find { |e| event_id.eql?(e.event_id) } or raise EventNotFound.new(event_id)
|
61
61
|
end
|
62
62
|
|
63
63
|
def get_all_streams
|
64
|
-
[Stream.new("all")] + streams.keys.map { |name| Stream.new(name) }
|
64
|
+
[Stream.new("all")] + @streams.keys.map { |name| Stream.new(name) }
|
65
65
|
end
|
66
66
|
|
67
67
|
private
|
68
|
-
attr_accessor :streams, :all
|
69
68
|
|
70
69
|
def normalize_to_array(events)
|
71
70
|
return *events
|
@@ -107,12 +106,12 @@ module RubyEventStore
|
|
107
106
|
events.each do |event|
|
108
107
|
raise EventDuplicatedInStream if stream.any?{|ev| ev.event_id.eql?(event.event_id) }
|
109
108
|
if include_global
|
110
|
-
raise EventDuplicatedInStream if all.any?{|ev| ev.event_id.eql?(event.event_id) }
|
111
|
-
all.push(event)
|
109
|
+
raise EventDuplicatedInStream if @all.any?{|ev| ev.event_id.eql?(event.event_id) }
|
110
|
+
@all.push(event)
|
112
111
|
end
|
113
112
|
stream.push(event)
|
114
113
|
end
|
115
|
-
streams[stream_name] = stream
|
114
|
+
@streams[stream_name] = stream
|
116
115
|
self
|
117
116
|
end
|
118
117
|
|
@@ -12,24 +12,20 @@ module RubyEventStore
|
|
12
12
|
def event_to_serialized_record(domain_event)
|
13
13
|
SerializedRecord.new(
|
14
14
|
event_id: domain_event.event_id,
|
15
|
-
metadata: serializer.dump(domain_event.metadata),
|
16
|
-
data: serializer.dump(domain_event.data),
|
15
|
+
metadata: @serializer.dump(domain_event.metadata),
|
16
|
+
data: @serializer.dump(domain_event.data),
|
17
17
|
event_type: domain_event.class.name
|
18
18
|
)
|
19
19
|
end
|
20
20
|
|
21
21
|
def serialized_record_to_event(record)
|
22
|
-
event_type = events_class_remapping.fetch(record.event_type) { record.event_type }
|
22
|
+
event_type = @events_class_remapping.fetch(record.event_type) { record.event_type }
|
23
23
|
ActiveSupport::Inflector.constantize(event_type).new(
|
24
24
|
event_id: record.event_id,
|
25
|
-
metadata: serializer.load(record.metadata),
|
26
|
-
data: serializer.load(record.data)
|
25
|
+
metadata: @serializer.load(record.metadata),
|
26
|
+
data: @serializer.load(record.data)
|
27
27
|
)
|
28
28
|
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
attr_reader :serializer, :events_class_remapping
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
@@ -23,25 +23,24 @@ module RubyEventStore
|
|
23
23
|
|
24
24
|
def notify_subscribers(event)
|
25
25
|
all_subscribers_for(event.class).each do |subscriber|
|
26
|
-
dispatcher.call(subscriber, event)
|
26
|
+
@dispatcher.call(subscriber, event)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
31
|
-
attr_reader :subscribers, :dispatcher
|
32
31
|
|
33
32
|
def verify_subscriber(subscriber)
|
34
33
|
raise SubscriberNotExist if subscriber.nil?
|
35
|
-
dispatcher.verify(subscriber)
|
34
|
+
@dispatcher.verify(subscriber)
|
36
35
|
end
|
37
36
|
|
38
37
|
def subscribe(subscriber, event_types)
|
39
|
-
event_types.each{ |type| subscribers[type.name] << subscriber }
|
40
|
-
->() {event_types.each{ |type| subscribers.fetch(type.name).delete(subscriber) } }
|
38
|
+
event_types.each{ |type| @subscribers[type.name] << subscriber }
|
39
|
+
->() {event_types.each{ |type| @subscribers.fetch(type.name).delete(subscriber) } }
|
41
40
|
end
|
42
41
|
|
43
42
|
def all_subscribers_for(event_type)
|
44
|
-
subscribers[event_type.name] + @global_subscribers
|
43
|
+
@subscribers[event_type.name] + @global_subscribers
|
45
44
|
end
|
46
45
|
end
|
47
46
|
end
|
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.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkency
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
131
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.
|
132
|
+
rubygems_version: 2.7.5
|
133
133
|
signing_key:
|
134
134
|
specification_version: 4
|
135
135
|
summary: Event Store in Ruby
|