sandthorn 0.0.1 → 0.0.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/.travis.yml +5 -0
- data/Gemfile.lock +21 -3
- data/README.md +45 -32
- data/Rakefile +16 -0
- data/lib/sandthorn.rb +2 -2
- data/lib/sandthorn/aggregate_root_base.rb +17 -24
- data/lib/sandthorn/version.rb +1 -1
- data/sandthorn.gemspec +1 -1
- data/spec/aggregate_delta_spec.rb +0 -1
- data/spec/aggregate_snapshot_spec.rb +1 -2
- data/spec/event_inspector_spec.rb +4 -0
- data/spec/spec_helper.rb +3 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a30c37a7e24b7962887842ee014817b9af94aa2f
|
4
|
+
data.tar.gz: 0a297cdd2b5d9b6fa6a5d0873f3ab6d42ca3f572
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf09e9cf219afd1a273b3fe1da4e9434625c03e60dc0522cb4133c61dfdec2a4f9713709c8a2f1446dd5c883c5a817b8380829f64dae6c65bfe25715f8699a46
|
7
|
+
data.tar.gz: e532a7430556572dd0c24c7e25a9a696e3d264f1abb424af7ab478e930070efbf6a9fc55075864b1307fdccebaa23144925326600bc35e3656fc2a85d07695a0
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sandthorn (0.0.
|
4
|
+
sandthorn (0.0.2)
|
5
5
|
dirty_hashy
|
6
|
-
uuidtools
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: https://rubygems.org/
|
@@ -18,12 +17,20 @@ GEM
|
|
18
17
|
autotest-standalone (4.5.11)
|
19
18
|
awesome_print (1.2.0)
|
20
19
|
coderay (1.1.0)
|
20
|
+
coveralls (0.7.0)
|
21
|
+
multi_json (~> 1.3)
|
22
|
+
rest-client
|
23
|
+
simplecov (>= 0.7)
|
24
|
+
term-ansicolor
|
25
|
+
thor
|
21
26
|
diff-lcs (1.2.5)
|
22
27
|
dirty_hashy (0.2.1)
|
23
28
|
activesupport
|
29
|
+
docile (1.1.3)
|
24
30
|
gem-release (0.7.1)
|
25
31
|
i18n (0.6.9)
|
26
32
|
method_source (0.8.2)
|
33
|
+
mime-types (2.2)
|
27
34
|
minitest (4.7.5)
|
28
35
|
multi_json (1.9.0)
|
29
36
|
pg (0.17.1)
|
@@ -35,6 +42,8 @@ GEM
|
|
35
42
|
pry (~> 0.9)
|
36
43
|
yard (~> 0.8)
|
37
44
|
rake (10.1.1)
|
45
|
+
rest-client (1.6.7)
|
46
|
+
mime-types (>= 1.16)
|
38
47
|
rspec (2.14.1)
|
39
48
|
rspec-core (~> 2.14.0)
|
40
49
|
rspec-expectations (~> 2.14.0)
|
@@ -47,12 +56,20 @@ GEM
|
|
47
56
|
pg
|
48
57
|
sequel
|
49
58
|
sequel (4.8.0)
|
59
|
+
simplecov (0.8.2)
|
60
|
+
docile (~> 1.1.0)
|
61
|
+
multi_json
|
62
|
+
simplecov-html (~> 0.8.0)
|
63
|
+
simplecov-html (0.8.0)
|
50
64
|
slop (3.5.0)
|
51
65
|
sqlite3 (1.3.9)
|
66
|
+
term-ansicolor (1.3.0)
|
67
|
+
tins (~> 1.0)
|
68
|
+
thor (0.19.1)
|
52
69
|
thread_safe (0.2.0)
|
53
70
|
atomic (>= 1.1.7, < 2)
|
71
|
+
tins (1.0.1)
|
54
72
|
tzinfo (0.3.39)
|
55
|
-
uuidtools (2.1.4)
|
56
73
|
yard (0.8.7.3)
|
57
74
|
|
58
75
|
PLATFORMS
|
@@ -62,6 +79,7 @@ DEPENDENCIES
|
|
62
79
|
autotest-standalone
|
63
80
|
awesome_print
|
64
81
|
bundler (~> 1.3)
|
82
|
+
coveralls
|
65
83
|
gem-release
|
66
84
|
pry
|
67
85
|
pry-doc
|
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
[](https://travis-ci.org/Sandthorn/sandthorn)
|
2
|
+
[](https://coveralls.io/r/Sandthorn/sandthorn?branch=master)
|
3
|
+
[](https://codeclimate.com/github/Sandthorn/sandthorn)
|
4
|
+
[](http://badge.fury.io/rb/sandthorn)
|
5
|
+
|
1
6
|
# Sandthorn Event Sourcing
|
2
|
-
A ruby
|
7
|
+
A ruby framework for saving an object's state as a series of events, and tracking non state changing events.
|
3
8
|
|
4
9
|
## What is Event Sourcing
|
5
10
|
|
@@ -13,53 +18,56 @@ _Example:_
|
|
13
18
|
|
14
19
|
```ruby
|
15
20
|
|
16
|
-
#Setup the Aggregate
|
21
|
+
# Setup the Aggregate
|
17
22
|
|
18
|
-
|
23
|
+
# The one available right now
|
24
|
+
require 'sandthorn'
|
25
|
+
require 'sandthorn_driver_sequel'
|
26
|
+
require 'sandthorn/aggregate_root_dirty_hashy'
|
19
27
|
|
20
28
|
class Ship
|
21
|
-
include Sandthorn::AggregateRoot::DirtyHashy
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
29
|
+
include Sandthorn::AggregateRoot::DirtyHashy
|
30
|
+
attr_reader :name
|
31
|
+
|
32
|
+
def initialize name: nil, shipping_company: nil
|
33
|
+
@name = name
|
34
|
+
end
|
35
|
+
|
36
|
+
# State-changing command
|
37
|
+
def rename! new_name: ""
|
38
|
+
unless new_name.empty? or new_name == name
|
39
|
+
@name = new_name
|
40
|
+
ship_was_renamed
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
# Commit the event and state-change is automatically recorded.
|
47
|
+
def ship_was_renamed
|
48
|
+
commit
|
49
|
+
end
|
40
50
|
end
|
41
51
|
|
42
|
-
#Setup the framework with the sequel driver for persistance
|
43
|
-
url = "
|
52
|
+
# Setup the framework with the sequel driver for persistance
|
53
|
+
url = "sqlite://spec/db/sequel_driver.sqlite3"
|
44
54
|
catch_all_config = [ { driver: SandthornDriverSequel.driver_from_url(url: url) } ]
|
45
55
|
Sandthorn.configuration = catch_all_config
|
46
56
|
|
47
|
-
#
|
57
|
+
# Migrate db schema for the sequel driver
|
48
58
|
migrator = SandthornDriverSequel::Migration.new url: url
|
49
59
|
SandthornDriverSequel.migrate_db url: url
|
50
60
|
|
51
|
-
#Usage
|
52
|
-
ship = Ship.new "Titanic"
|
53
|
-
ship.rename! "Vasa"
|
54
|
-
|
61
|
+
# Usage
|
62
|
+
ship = Ship.new name: "Titanic"
|
63
|
+
ship.rename! new_name: "Vasa"
|
64
|
+
|
55
65
|
ship.save
|
56
66
|
|
57
67
|
new_ship = Ship.find ship.id
|
58
68
|
puts ship.name
|
59
|
-
.
|
60
|
-
.
|
61
69
|
|
62
|
-
For more info look at the specs.
|
70
|
+
# For more info look at the specs.
|
63
71
|
|
64
72
|
```
|
65
73
|
|
@@ -81,6 +89,11 @@ Or install it yourself as:
|
|
81
89
|
|
82
90
|
TODO: Write usage instructions here
|
83
91
|
|
92
|
+
## Development
|
93
|
+
|
94
|
+
run:
|
95
|
+
`rake console`
|
96
|
+
|
84
97
|
## Contributing
|
85
98
|
|
86
99
|
1. Fork it
|
data/Rakefile
CHANGED
@@ -1 +1,17 @@
|
|
1
|
+
#!/usr/bin/env rake
|
1
2
|
require "bundler/gem_tasks"
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :default => :spec
|
8
|
+
|
9
|
+
task :console do
|
10
|
+
require 'ap'
|
11
|
+
require 'pry'
|
12
|
+
require 'pry/completion'
|
13
|
+
require 'bundler'
|
14
|
+
require 'sandthorn'
|
15
|
+
ARGV.clear
|
16
|
+
Pry.start
|
17
|
+
end
|
data/lib/sandthorn.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "sandthorn/version"
|
2
2
|
require "sandthorn/errors"
|
3
|
-
require 'uuidtools'
|
4
3
|
require 'yaml'
|
4
|
+
require 'securerandom'
|
5
5
|
|
6
6
|
module Sandthorn
|
7
7
|
class << self
|
@@ -27,7 +27,7 @@ module Sandthorn
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def generate_aggregate_id
|
30
|
-
|
30
|
+
SecureRandom.uuid
|
31
31
|
end
|
32
32
|
|
33
33
|
def get_aggregate_events aggregate_id, class_name
|
@@ -17,8 +17,6 @@ module Sandthorn
|
|
17
17
|
@aggregate_events = []
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
20
|
def save
|
23
21
|
aggregate_events.each do |event|
|
24
22
|
event[:event_data] = Sandthorn.serialize event[:event_args]
|
@@ -32,9 +30,9 @@ module Sandthorn
|
|
32
30
|
self
|
33
31
|
end
|
34
32
|
|
35
|
-
def commit *args
|
33
|
+
def commit *args, method_name: nil
|
36
34
|
increase_current_aggregate_version!
|
37
|
-
method_name =
|
35
|
+
method_name = caller_locations(1,1)[0].label unless method_name
|
38
36
|
aggregate_attribute_deltas = get_delta
|
39
37
|
|
40
38
|
unless aggregate_attribute_deltas.empty?
|
@@ -67,7 +65,7 @@ module Sandthorn
|
|
67
65
|
@@aggregate_trace_information = nil
|
68
66
|
@aggregate_trace_information = nil
|
69
67
|
end
|
70
|
-
|
68
|
+
|
71
69
|
def find aggregate_id
|
72
70
|
class_name = self.respond_to?(:name) ? self.name : self.class # to be able to extend a string for example.
|
73
71
|
events = Sandthorn.get_aggregate(aggregate_id, class_name)
|
@@ -80,15 +78,15 @@ module Sandthorn
|
|
80
78
|
def new *args
|
81
79
|
aggregate = super
|
82
80
|
aggregate.aggregate_base_initialize
|
81
|
+
|
83
82
|
aggregate.aggregate_trace @@aggregate_trace_information do |aggr|
|
84
83
|
aggr.aggregate_initialize
|
85
84
|
aggr.send :set_aggregate_id, Sandthorn.generate_aggregate_id
|
86
|
-
aggr.send :commit, *args
|
85
|
+
aggr.send :commit, *args, method_name: "new"
|
87
86
|
return aggr
|
88
87
|
end
|
89
88
|
end
|
90
89
|
|
91
|
-
|
92
90
|
def aggregate_build events
|
93
91
|
first_event = events.first()
|
94
92
|
current_aggregate_version = 0
|
@@ -96,10 +94,6 @@ module Sandthorn
|
|
96
94
|
aggregate = first_event[:event_args][0]
|
97
95
|
current_aggregate_version = aggregate.aggregate_originating_version
|
98
96
|
events.shift
|
99
|
-
# elsif first_event[:event_name] == "instance_extended_as_aggregate"
|
100
|
-
# aggregate = first_event[:event_args][0]
|
101
|
-
#aggregate.extend AggregateRoot
|
102
|
-
# events.pop
|
103
97
|
else
|
104
98
|
new_args = events.first()[:event_args][:method_args]
|
105
99
|
|
@@ -116,23 +110,20 @@ module Sandthorn
|
|
116
110
|
event_args = event[:event_args]
|
117
111
|
event_name = event[:event_name]
|
118
112
|
|
119
|
-
if event_name == "aggregate_set_from_snapshot"
|
120
|
-
#aggregate.send event_name,*event_args
|
121
|
-
#set the attribute hash instead of instance varaibles directly
|
122
|
-
next
|
123
|
-
end
|
113
|
+
next if event_name == "aggregate_set_from_snapshot"
|
124
114
|
next if event_name == "instance_extended_as_aggregate"
|
125
115
|
|
126
116
|
attribute_deltas = event_args[:attribute_deltas]
|
127
|
-
|
117
|
+
|
118
|
+
unless event[:aggregate_version].nil?
|
128
119
|
current_aggregate_version = event[:aggregate_version]
|
129
120
|
end
|
130
121
|
|
131
|
-
|
132
|
-
deltas = {}
|
133
|
-
|
134
|
-
deltas[delta[:attribute_name]] = delta[:new_value]
|
122
|
+
unless attribute_deltas.nil?
|
123
|
+
deltas = attribute_deltas.each_with_object({}) do |delta, acc|
|
124
|
+
acc[delta[:attribute_name]] = delta[:new_value]
|
135
125
|
end
|
126
|
+
|
136
127
|
attributes.merge! deltas
|
137
128
|
end
|
138
129
|
end
|
@@ -143,7 +134,7 @@ module Sandthorn
|
|
143
134
|
aggregate
|
144
135
|
end
|
145
136
|
end
|
146
|
-
|
137
|
+
|
147
138
|
private
|
148
139
|
|
149
140
|
def set_instance_variables! attributes
|
@@ -153,7 +144,9 @@ module Sandthorn
|
|
153
144
|
end
|
154
145
|
|
155
146
|
def extract_relevant_aggregate_instance_variables
|
156
|
-
instance_variables.select
|
147
|
+
instance_variables.select do |i|
|
148
|
+
i.to_s != "@hashy" && (!i.to_s.start_with?("@aggregate_") || i.to_s == "@aggregate_id")
|
149
|
+
end
|
157
150
|
end
|
158
151
|
|
159
152
|
def set_orginating_aggregate_version! aggregate_version
|
@@ -183,4 +176,4 @@ module Sandthorn
|
|
183
176
|
|
184
177
|
end
|
185
178
|
end
|
186
|
-
end
|
179
|
+
end
|
data/lib/sandthorn/version.rb
CHANGED
data/sandthorn.gemspec
CHANGED
@@ -27,9 +27,9 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "awesome_print"
|
28
28
|
spec.add_development_dependency "autotest-standalone"
|
29
29
|
spec.add_development_dependency "sqlite3"
|
30
|
+
spec.add_development_dependency "coveralls"
|
30
31
|
spec.add_development_dependency "sandthorn_driver_sequel"
|
31
32
|
|
32
33
|
spec.add_runtime_dependency "dirty_hashy"
|
33
|
-
spec.add_runtime_dependency "uuidtools"
|
34
34
|
|
35
35
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'uuidtools'
|
3
2
|
require 'sandthorn/aggregate_root_dirty_hashy'
|
4
3
|
require 'sandthorn/aggregate_root_snapshot'
|
5
4
|
require 'date'
|
@@ -50,7 +49,7 @@ class VisaCardTransactionGateway
|
|
50
49
|
@visa_connector = "foo_bar"
|
51
50
|
end
|
52
51
|
def charge_card visa_card_number, merchant_id, amount
|
53
|
-
transaction_id =
|
52
|
+
transaction_id = SecureRandom.uuid
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
@@ -52,6 +52,10 @@ module Sandthorn
|
|
52
52
|
context "with no tracing information" do
|
53
53
|
let(:subject) { aggregate.this_is_an_event;aggregate }
|
54
54
|
|
55
|
+
it "should have the new event" do
|
56
|
+
subject.has_event?(:new).should be_true
|
57
|
+
end
|
58
|
+
|
55
59
|
it "should report true on has_unsaved_event? :this_is_an_event" do
|
56
60
|
subject.has_unsaved_event?(:this_is_an_event).should be_true
|
57
61
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,11 +4,13 @@
|
|
4
4
|
# loaded once.
|
5
5
|
#
|
6
6
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require 'coveralls'
|
7
8
|
require "ap"
|
8
9
|
require "bundler"
|
9
10
|
require "sandthorn_driver_sequel"
|
10
11
|
|
11
12
|
Bundler.require
|
13
|
+
Coveralls.wear!
|
12
14
|
|
13
15
|
module Helpers
|
14
16
|
def class_including(mod)
|
@@ -39,4 +41,4 @@ def sqlite_store_setup
|
|
39
41
|
migrator = SandthornDriverSequel::Migration.new url: url
|
40
42
|
SandthornDriverSequel.migrate_db url: url
|
41
43
|
migrator.send(:clear_for_test)
|
42
|
-
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sandthorn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lars Krantz
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -138,7 +138,7 @@ dependencies:
|
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
|
-
name:
|
141
|
+
name: coveralls
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
144
|
- - ">="
|
@@ -152,13 +152,13 @@ dependencies:
|
|
152
152
|
- !ruby/object:Gem::Version
|
153
153
|
version: '0'
|
154
154
|
- !ruby/object:Gem::Dependency
|
155
|
-
name:
|
155
|
+
name: sandthorn_driver_sequel
|
156
156
|
requirement: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
158
|
- - ">="
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
|
-
type: :
|
161
|
+
type: :development
|
162
162
|
prerelease: false
|
163
163
|
version_requirements: !ruby/object:Gem::Requirement
|
164
164
|
requirements:
|
@@ -166,7 +166,7 @@ dependencies:
|
|
166
166
|
- !ruby/object:Gem::Version
|
167
167
|
version: '0'
|
168
168
|
- !ruby/object:Gem::Dependency
|
169
|
-
name:
|
169
|
+
name: dirty_hashy
|
170
170
|
requirement: !ruby/object:Gem::Requirement
|
171
171
|
requirements:
|
172
172
|
- - ">="
|
@@ -192,6 +192,7 @@ files:
|
|
192
192
|
- ".rspec"
|
193
193
|
- ".ruby-gemset"
|
194
194
|
- ".ruby-version"
|
195
|
+
- ".travis.yml"
|
195
196
|
- Gemfile
|
196
197
|
- Gemfile.lock
|
197
198
|
- Gemfile.lock.old
|