ruby_cqrs 0.2.1 → 0.2.2
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/lib/ruby_cqrs/data/in_memory_event_store.rb +14 -0
- data/lib/ruby_cqrs/data/serialization.rb +0 -4
- data/lib/ruby_cqrs/domain/aggregate_repository.rb +4 -4
- data/lib/ruby_cqrs/version.rb +1 -1
- data/spec/feature/basic_usage_spec.rb +1 -1
- data/spec/unit/aggregate_repository_spec.rb +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5defe0400414fa278a0716341c10d41dcf050a9
|
4
|
+
data.tar.gz: 303081f7864984adc5675514c0a3355538f67c5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb699d7dda967e16639dc5d28b640845941a6c0545ffb4108e9338242352b0bd7a92253ef3b8329d0717c37ca44eb85ffb559c7b0d4874b25d1b70c6b9611bd4
|
7
|
+
data.tar.gz: e975d958f11be45a15dc16b27ab410546d470a80d579dd60cdc94b5bb5a38a25665ac2f0658c7d7d74f8e973e5b8e68428ff28bca43586ccb463069b7e204230
|
@@ -9,6 +9,18 @@ module RubyCqrs
|
|
9
9
|
@snapshot_store = {}
|
10
10
|
end
|
11
11
|
|
12
|
+
# the returned format is as bellow
|
13
|
+
# { :aggregate_id => some_aggregtate_id(uuid),
|
14
|
+
# :aggregate_type => the full qualified name of the aggregate type(string),
|
15
|
+
# :events => [ {:aggregate_id => the aggregate_id of the event belongs to(uuid),
|
16
|
+
# :event_type => the full qualified name of the event type(string),
|
17
|
+
# :version => the version number of the event(integer),
|
18
|
+
# :data => protobuf encoded content of the event object(string)}, ..., {} ],
|
19
|
+
# :snapshot => { :state_type => the full qualified name of the snapshot type(string),
|
20
|
+
# :version => the version number of the aggregate when snapshot(integer),
|
21
|
+
# :data => protobuf encoded content of the snapshot object(string)} }
|
22
|
+
# the snapshot object could be null; and the events array should return events which has a version
|
23
|
+
# number greater than the version number of the returning snapshot, if any.
|
12
24
|
def load_by guid, command_context
|
13
25
|
key = guid.to_sym
|
14
26
|
state = { :aggregate_id => guid,
|
@@ -23,6 +35,8 @@ module RubyCqrs
|
|
23
35
|
state
|
24
36
|
end
|
25
37
|
|
38
|
+
# the changes are defined as an array of aggregate change,
|
39
|
+
# each change's format is identical to what above load_by returns
|
26
40
|
def save changes, command_context
|
27
41
|
changes.each do |change|
|
28
42
|
key = change[:aggregate_id].to_sym
|
@@ -2,9 +2,9 @@ require 'active_support/inflector'
|
|
2
2
|
require_relative '../guid'
|
3
3
|
|
4
4
|
module RubyCqrs
|
5
|
-
class
|
5
|
+
class AggregateNotFoundError < Error; end
|
6
6
|
class AggregateConcurrencyError < Error; end
|
7
|
-
class
|
7
|
+
class AggregateDuplicationError < Error; end
|
8
8
|
|
9
9
|
module Domain
|
10
10
|
class AggregateRepository
|
@@ -15,7 +15,7 @@ module RubyCqrs
|
|
15
15
|
raise ArgumentError unless Guid.validate? aggregate_id
|
16
16
|
|
17
17
|
state = @event_store.load_by(aggregate_id, @command_context)
|
18
|
-
raise
|
18
|
+
raise AggregateNotFoundError if (state.nil? or state[:aggregate_type].nil? or\
|
19
19
|
((state[:events].nil? or state[:events].empty?) and state[:snapshot].nil?))
|
20
20
|
|
21
21
|
create_instance_from state
|
@@ -59,7 +59,7 @@ module RubyCqrs
|
|
59
59
|
|
60
60
|
def verify_uniqueness_of aggregates
|
61
61
|
uniq_array = aggregates.uniq { |aggregate| aggregate.aggregate_id }
|
62
|
-
raise
|
62
|
+
raise AggregateDuplicationError unless uniq_array.size == aggregates.size
|
63
63
|
end
|
64
64
|
|
65
65
|
def prep_changes_for aggregates
|
data/lib/ruby_cqrs/version.rb
CHANGED
@@ -15,7 +15,7 @@ class Customer
|
|
15
15
|
|
16
16
|
attr_reader :name, :credit
|
17
17
|
|
18
|
-
# unfortunately, you should not try to define your own initialize method
|
18
|
+
# unfortunately, you should not try to define your own initialize method with parameters
|
19
19
|
# at the time being, it could potentially cause error with aggregate_repository
|
20
20
|
# when it tries to instantiate an aggregate back to live.
|
21
21
|
# Still looking for better way to do this.
|
@@ -64,9 +64,9 @@ describe RubyCqrs::Domain::AggregateRepository do
|
|
64
64
|
let(:matches_nothing_repository) { RubyCqrs::Domain::AggregateRepository.new\
|
65
65
|
empty_event_store, command_context }
|
66
66
|
|
67
|
-
it 'raises error of type
|
67
|
+
it 'raises error of type AggregateNotFoundError' do
|
68
68
|
expect { matches_nothing_repository.find_by(aggregate_id) }.to \
|
69
|
-
raise_error(RubyCqrs::
|
69
|
+
raise_error(RubyCqrs::AggregateNotFoundError)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -183,13 +183,13 @@ describe RubyCqrs::Domain::AggregateRepository do
|
|
183
183
|
end
|
184
184
|
|
185
185
|
context 'when saving 2 instances of the same aggregate' do
|
186
|
-
it 'raises
|
186
|
+
it 'raises AggregateDuplicationError and nothing should be changed' do
|
187
187
|
aggregate_1 = aggregate_type.new
|
188
188
|
aggregate_2 = aggregate_1.dup
|
189
189
|
aggregate_1.test_fire
|
190
190
|
aggregate_2.test_fire
|
191
191
|
aggregates = [ aggregate_1, aggregate_2 ]
|
192
|
-
expect{ repository.save aggregates }.to raise_error(RubyCqrs::
|
192
|
+
expect{ repository.save aggregates }.to raise_error(RubyCqrs::AggregateDuplicationError)
|
193
193
|
expect(aggregate_1.version).to_not eq(aggregate_1.instance_variable_get(:@source_verrsion))
|
194
194
|
expect(aggregate_2.version).to_not eq(aggregate_2.instance_variable_get(:@source_verrsion))
|
195
195
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_cqrs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raven Chen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uuidtools
|
@@ -107,7 +107,7 @@ rubyforge_project:
|
|
107
107
|
rubygems_version: 2.4.6
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
|
-
summary: ruby_cqrs-0.2.
|
110
|
+
summary: ruby_cqrs-0.2.2
|
111
111
|
test_files:
|
112
112
|
- spec/feature/basic_usage_spec.rb
|
113
113
|
- spec/feature/snapshot_spec.rb
|