ruby_cqrs 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5f70e7b70c21215981195e374595fce852f0d94
4
- data.tar.gz: 5312d18d87f660591396ca99cc120edb5e63bfb1
3
+ metadata.gz: e5defe0400414fa278a0716341c10d41dcf050a9
4
+ data.tar.gz: 303081f7864984adc5675514c0a3355538f67c5c
5
5
  SHA512:
6
- metadata.gz: 95dbd4d1ebc007450eba00a2f7bc4e8cf2dd47b439299bed29ee1bea5138b09e3058a68528f214345ae7cfdca02df8b78dead78037e810e5f6dcc5fb1a694a41
7
- data.tar.gz: 0f4ea2e1eea528a598fa1e34a760994a51276e79c929a7078767ae7e5a4c31afffe5fad7c732ce1c9988618dd5a78a98e029a4ea955ced1c6a30550902dbea37
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
@@ -13,11 +13,7 @@ module RubyCqrs
13
13
  raise ObjectNotEncodableError
14
14
  end
15
15
  end
16
- end
17
- end
18
16
 
19
- module RubyCqrs
20
- module Data
21
17
  module Decodable
22
18
 
23
19
  def try_decode type_str, data
@@ -2,9 +2,9 @@ require 'active_support/inflector'
2
2
  require_relative '../guid'
3
3
 
4
4
  module RubyCqrs
5
- class AggregateNotFound < Error; end
5
+ class AggregateNotFoundError < Error; end
6
6
  class AggregateConcurrencyError < Error; end
7
- class AggregateInstanceDuplicatedError < Error; end
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 AggregateNotFound if (state.nil? or state[:aggregate_type].nil? or\
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 AggregateInstanceDuplicatedError unless uniq_array.size == aggregates.size
62
+ raise AggregateDuplicationError unless uniq_array.size == aggregates.size
63
63
  end
64
64
 
65
65
  def prep_changes_for aggregates
@@ -1,3 +1,3 @@
1
1
  module RubyCqrs # :nodoc:
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -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 AggregateNotFound' do
67
+ it 'raises error of type AggregateNotFoundError' do
68
68
  expect { matches_nothing_repository.find_by(aggregate_id) }.to \
69
- raise_error(RubyCqrs::AggregateNotFound)
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 AggregateInstanceDuplicatedError and nothing should be changed' do
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::AggregateInstanceDuplicatedError)
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.1
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-14 00:00:00.000000000 Z
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.1
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