sandthorn 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +38 -29
- data/README.md +4 -3
- data/lib/sandthorn.rb +60 -14
- data/lib/sandthorn/aggregate_root_base.rb +7 -1
- data/lib/sandthorn/aggregate_root_snapshot.rb +2 -2
- data/lib/sandthorn/version.rb +1 -1
- data/sandthorn.gemspec +1 -0
- data/spec/spec_helper.rb +4 -0
- metadata +33 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1029a5956517741e56d4d6803c8a505b08a4c2f3
|
4
|
+
data.tar.gz: ecd66efba1d4f987cae937822730c1b407050acc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31df15e4008339c0281432f0e0fd1232fbfcfb4227a020ef5c7842fb80eb3ceb989de32ad34d05be2fe782889761b9a797f6cdb6128d4f2495142d2d79773905
|
7
|
+
data.tar.gz: f2b21aa607186f555900725b77de6d4e8fba666e441eae7a4ae7a1882e1feb61e413905f143a80fb4306ca2feedc6e572d82fd5c7716e2fa986a42d710b555db
|
data/Gemfile.lock
CHANGED
@@ -1,27 +1,31 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sandthorn (0.
|
4
|
+
sandthorn (0.8.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
autotest-standalone (4.5.11)
|
10
|
-
awesome_print (1.
|
10
|
+
awesome_print (1.6.1)
|
11
11
|
coderay (1.1.0)
|
12
|
-
coveralls (0.7.
|
13
|
-
multi_json (~> 1.
|
14
|
-
rest-client
|
15
|
-
simplecov (
|
16
|
-
term-ansicolor
|
17
|
-
thor
|
12
|
+
coveralls (0.7.12)
|
13
|
+
multi_json (~> 1.10)
|
14
|
+
rest-client (>= 1.6.8, < 2)
|
15
|
+
simplecov (~> 0.9.1)
|
16
|
+
term-ansicolor (~> 1.3)
|
17
|
+
thor (~> 0.19.1)
|
18
18
|
diff-lcs (1.2.5)
|
19
19
|
docile (1.1.5)
|
20
|
+
domain_name (0.5.23)
|
21
|
+
unf (>= 0.0.5, < 1.0.0)
|
20
22
|
gem-release (0.7.3)
|
23
|
+
http-cookie (1.0.2)
|
24
|
+
domain_name (~> 0.5)
|
21
25
|
method_source (0.8.2)
|
22
26
|
mime-types (2.4.3)
|
23
|
-
multi_json (1.
|
24
|
-
netrc (0.
|
27
|
+
multi_json (1.11.0)
|
28
|
+
netrc (0.10.3)
|
25
29
|
pg (0.18.1)
|
26
30
|
pry (0.10.1)
|
27
31
|
coderay (~> 1.1.0)
|
@@ -30,38 +34,43 @@ GEM
|
|
30
34
|
pry-doc (0.6.0)
|
31
35
|
pry (~> 0.9)
|
32
36
|
yard (~> 0.8)
|
33
|
-
rake (10.
|
34
|
-
rest-client (1.
|
37
|
+
rake (10.4.2)
|
38
|
+
rest-client (1.8.0)
|
39
|
+
http-cookie (>= 1.0.2, < 2.0)
|
35
40
|
mime-types (>= 1.16, < 3.0)
|
36
41
|
netrc (~> 0.7)
|
37
|
-
rspec (3.
|
38
|
-
rspec-core (~> 3.
|
39
|
-
rspec-expectations (~> 3.
|
40
|
-
rspec-mocks (~> 3.
|
41
|
-
rspec-core (3.
|
42
|
-
rspec-support (~> 3.
|
43
|
-
rspec-expectations (3.
|
42
|
+
rspec (3.2.0)
|
43
|
+
rspec-core (~> 3.2.0)
|
44
|
+
rspec-expectations (~> 3.2.0)
|
45
|
+
rspec-mocks (~> 3.2.0)
|
46
|
+
rspec-core (3.2.2)
|
47
|
+
rspec-support (~> 3.2.0)
|
48
|
+
rspec-expectations (3.2.0)
|
44
49
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
-
rspec-support (~> 3.
|
46
|
-
rspec-mocks (3.1
|
47
|
-
|
48
|
-
|
50
|
+
rspec-support (~> 3.2.0)
|
51
|
+
rspec-mocks (3.2.1)
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
+
rspec-support (~> 3.2.0)
|
54
|
+
rspec-support (3.2.2)
|
49
55
|
sandthorn_driver_sequel (2.0.0)
|
50
56
|
pg
|
51
57
|
sequel (~> 4.17)
|
52
58
|
sequel (4.20.0)
|
53
|
-
simplecov (0.9.
|
59
|
+
simplecov (0.9.2)
|
54
60
|
docile (~> 1.1.0)
|
55
61
|
multi_json (~> 1.0)
|
56
|
-
simplecov-html (~> 0.
|
57
|
-
simplecov-html (0.
|
62
|
+
simplecov-html (~> 0.9.0)
|
63
|
+
simplecov-html (0.9.0)
|
58
64
|
slop (3.6.0)
|
59
|
-
sqlite3 (1.3.
|
65
|
+
sqlite3 (1.3.10)
|
60
66
|
term-ansicolor (1.3.0)
|
61
67
|
tins (~> 1.0)
|
62
68
|
thor (0.19.1)
|
63
|
-
tins (1.3.
|
64
|
-
|
69
|
+
tins (1.3.5)
|
70
|
+
unf (0.1.4)
|
71
|
+
unf_ext
|
72
|
+
unf_ext (0.0.6)
|
73
|
+
yard (0.8.7.6)
|
65
74
|
|
66
75
|
PLATFORMS
|
67
76
|
ruby
|
data/README.md
CHANGED
@@ -130,11 +130,12 @@ The driver is configured when your application launches. Here's an example of ho
|
|
130
130
|
```ruby
|
131
131
|
url = "sqlite://spec/db/sequel_driver.sqlite3"
|
132
132
|
driver = SandthornDriverSequel.driver_from_url(url: url)
|
133
|
-
|
134
|
-
|
133
|
+
Sandthorn.configure do |conf|
|
134
|
+
conf.event_stores = { default: driver }
|
135
|
+
end
|
135
136
|
```
|
136
137
|
|
137
|
-
First we specify the path to the sqlite3 database in the `url` variable. Secondly, the specific driver is instantiated with the `url`. Hence, the driver could be instantiated using a different configuration, for example, an address to a Postgres database. Finally, `Sandthorn.configure` accepts a keyword list with options.
|
138
|
+
First we specify the path to the sqlite3 database in the `url` variable. Secondly, the specific driver is instantiated with the `url`. Hence, the driver could be instantiated using a different configuration, for example, an address to a Postgres database. Finally, `Sandthorn.configure` accepts a keyword list with options. It´s here the driver is bound to Sandthorn via a context.
|
138
139
|
|
139
140
|
The first time you use the Sequel driver it is necessary to install the database schema.
|
140
141
|
|
data/lib/sandthorn.rb
CHANGED
@@ -10,7 +10,7 @@ module Sandthorn
|
|
10
10
|
class << self
|
11
11
|
extend Forwardable
|
12
12
|
|
13
|
-
def_delegators :configuration, :event_stores
|
13
|
+
def_delegators :configuration, :event_stores, :serialize, :deserialize, :serialize_snapshot, :deserialize_snapshot
|
14
14
|
|
15
15
|
def default_event_store
|
16
16
|
event_stores.default_store
|
@@ -28,19 +28,7 @@ module Sandthorn
|
|
28
28
|
@configuration ||= Configuration.new
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
#Marshal.dump(data)
|
33
|
-
YAML::dump(data)
|
34
|
-
#Oj.dump(data)
|
35
|
-
#MessagePack.pack(data, symbolize_keys: true)
|
36
|
-
end
|
37
|
-
|
38
|
-
def deserialize data
|
39
|
-
#Marshal.load(data)
|
40
|
-
YAML::load(data)
|
41
|
-
#Oj.load(data)
|
42
|
-
#MessagePack.unpack(data, symbolize_keys: true)
|
43
|
-
end
|
31
|
+
|
44
32
|
|
45
33
|
def generate_aggregate_id
|
46
34
|
SecureRandom.uuid
|
@@ -122,6 +110,64 @@ module Sandthorn
|
|
122
110
|
def event_store=(store)
|
123
111
|
@event_stores = EventStores.new(store)
|
124
112
|
end
|
113
|
+
|
114
|
+
def serializer=(block)
|
115
|
+
@serializer = block if block.is_a? Proc
|
116
|
+
end
|
117
|
+
|
118
|
+
def deserializer=(block)
|
119
|
+
@deserializer = block if block.is_a? Proc
|
120
|
+
end
|
121
|
+
|
122
|
+
def serializer
|
123
|
+
@serializer || default_serializer
|
124
|
+
end
|
125
|
+
|
126
|
+
def deserializer
|
127
|
+
@deserializer || default_deserializer
|
128
|
+
end
|
129
|
+
|
130
|
+
def default_serializer
|
131
|
+
-> (data) { YAML.dump(data) }
|
132
|
+
end
|
133
|
+
|
134
|
+
def default_deserializer
|
135
|
+
-> (data) { YAML.load(data) }
|
136
|
+
end
|
137
|
+
|
138
|
+
def serialize(data)
|
139
|
+
serializer.call(data)
|
140
|
+
end
|
141
|
+
|
142
|
+
def deserialize(data)
|
143
|
+
deserializer.call(data)
|
144
|
+
end
|
145
|
+
|
146
|
+
def snapshot_serializer=(block)
|
147
|
+
@snapshot_serializer = block if block.is_a? Proc
|
148
|
+
end
|
149
|
+
|
150
|
+
def snapshot_deserializer=(block)
|
151
|
+
@snapshot_deserializer = block if block.is_a? Proc
|
152
|
+
end
|
153
|
+
|
154
|
+
def snapshot_serializer
|
155
|
+
@snapshot_serializer || default_serializer
|
156
|
+
end
|
157
|
+
|
158
|
+
def snapshot_deserializer
|
159
|
+
@snapshot_deserializer || default_deserializer
|
160
|
+
end
|
161
|
+
|
162
|
+
def serialize_snapshot(data)
|
163
|
+
snapshot_serializer.call(data)
|
164
|
+
end
|
165
|
+
|
166
|
+
def deserialize_snapshot data
|
167
|
+
snapshot_deserializer.call(data)
|
168
|
+
end
|
169
|
+
|
170
|
+
|
125
171
|
alias_method :event_stores=, :event_store=
|
126
172
|
end
|
127
173
|
end
|
@@ -108,10 +108,16 @@ module Sandthorn
|
|
108
108
|
unless events && !events.empty?
|
109
109
|
raise Sandthorn::Errors::AggregateNotFound
|
110
110
|
end
|
111
|
+
|
112
|
+
if first_event_snapshot?(events)
|
113
|
+
transformed_snapshot_event = events.first.merge(event_args: Sandthorn.deserialize_snapshot(events.first[:event_data]))
|
114
|
+
events.shift
|
115
|
+
end
|
116
|
+
|
111
117
|
transformed_events = events.map do |e|
|
112
118
|
e.merge(event_args: Sandthorn.deserialize(e[:event_data]))
|
113
119
|
end
|
114
|
-
aggregate_build transformed_events
|
120
|
+
aggregate_build ([transformed_snapshot_event] + transformed_events).compact
|
115
121
|
end
|
116
122
|
|
117
123
|
def new *args
|
@@ -25,7 +25,7 @@ module Sandthorn
|
|
25
25
|
unless aggregate_snapshot
|
26
26
|
raise Errors::SnapshotError, "No snapshot has been created!"
|
27
27
|
end
|
28
|
-
@aggregate_snapshot[:event_data] = Sandthorn.
|
28
|
+
@aggregate_snapshot[:event_data] = Sandthorn.serialize_snapshot @aggregate_snapshot[:event_args]
|
29
29
|
@aggregate_snapshot[:event_args] = nil
|
30
30
|
Sandthorn.save_snapshot(aggregate_snapshot: @aggregate_snapshot, aggregate_id: @aggregate_id, aggregate_type: self.class)
|
31
31
|
@aggregate_snapshot = nil
|
@@ -41,7 +41,7 @@ module Sandthorn
|
|
41
41
|
end
|
42
42
|
|
43
43
|
@aggregate_snapshot[:event_data] = Sandthorn
|
44
|
-
.
|
44
|
+
.serialize_snapshot aggregate_snapshot[:event_args]
|
45
45
|
|
46
46
|
@aggregate_snapshot[:event_args] = nil
|
47
47
|
Sandthorn.save_snapshot aggregate_snapshot, aggregate_id
|
data/lib/sandthorn/version.rb
CHANGED
data/sandthorn.gemspec
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -40,6 +40,10 @@ def sqlite_store_setup
|
|
40
40
|
driver = SandthornDriverSequel.driver_from_url(url: url)
|
41
41
|
Sandthorn.configure do |c|
|
42
42
|
c.event_store = driver
|
43
|
+
c.serializer = Proc.new { |data| YAML::dump(data) }
|
44
|
+
c.deserializer = Proc.new { |data| YAML::load(data) }
|
45
|
+
c.snapshot_serializer = Proc.new { |data| YAML::dump(data) }
|
46
|
+
c.snapshot_deserializer = Proc.new { |data| YAML::load(data) }
|
43
47
|
end
|
44
48
|
migrator = SandthornDriverSequel::Migration.new url: url
|
45
49
|
SandthornDriverSequel.migrate_db url: url
|
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.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lars Krantz
|
@@ -10,160 +10,160 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-05-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - ~>
|
19
|
+
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '1.3'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- - ~>
|
26
|
+
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '1.3'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rake
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- -
|
33
|
+
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '0'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: rspec
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - ~>
|
47
|
+
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '3.0'
|
50
50
|
type: :development
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - ~>
|
54
|
+
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '3.0'
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: gem-release
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- -
|
61
|
+
- - ">="
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '0'
|
64
64
|
type: :development
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- -
|
68
|
+
- - ">="
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: pry
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
|
-
- -
|
75
|
+
- - ">="
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
|
-
- -
|
82
|
+
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: pry-doc
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
|
-
- -
|
89
|
+
- - ">="
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
type: :development
|
93
93
|
prerelease: false
|
94
94
|
version_requirements: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
|
-
- -
|
96
|
+
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
99
|
- !ruby/object:Gem::Dependency
|
100
100
|
name: awesome_print
|
101
101
|
requirement: !ruby/object:Gem::Requirement
|
102
102
|
requirements:
|
103
|
-
- -
|
103
|
+
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
type: :development
|
107
107
|
prerelease: false
|
108
108
|
version_requirements: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
|
-
- -
|
110
|
+
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: autotest-standalone
|
115
115
|
requirement: !ruby/object:Gem::Requirement
|
116
116
|
requirements:
|
117
|
-
- -
|
117
|
+
- - ">="
|
118
118
|
- !ruby/object:Gem::Version
|
119
119
|
version: '0'
|
120
120
|
type: :development
|
121
121
|
prerelease: false
|
122
122
|
version_requirements: !ruby/object:Gem::Requirement
|
123
123
|
requirements:
|
124
|
-
- -
|
124
|
+
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
128
|
name: sqlite3
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
|
-
- -
|
131
|
+
- - ">="
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '0'
|
134
134
|
type: :development
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
137
|
requirements:
|
138
|
-
- -
|
138
|
+
- - ">="
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
141
|
- !ruby/object:Gem::Dependency
|
142
142
|
name: coveralls
|
143
143
|
requirement: !ruby/object:Gem::Requirement
|
144
144
|
requirements:
|
145
|
-
- -
|
145
|
+
- - ">="
|
146
146
|
- !ruby/object:Gem::Version
|
147
147
|
version: '0'
|
148
148
|
type: :development
|
149
149
|
prerelease: false
|
150
150
|
version_requirements: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
|
-
- -
|
152
|
+
- - ">="
|
153
153
|
- !ruby/object:Gem::Version
|
154
154
|
version: '0'
|
155
155
|
- !ruby/object:Gem::Dependency
|
156
156
|
name: sandthorn_driver_sequel
|
157
157
|
requirement: !ruby/object:Gem::Requirement
|
158
158
|
requirements:
|
159
|
-
- - ~>
|
159
|
+
- - "~>"
|
160
160
|
- !ruby/object:Gem::Version
|
161
161
|
version: '2.0'
|
162
162
|
type: :development
|
163
163
|
prerelease: false
|
164
164
|
version_requirements: !ruby/object:Gem::Requirement
|
165
165
|
requirements:
|
166
|
-
- - ~>
|
166
|
+
- - "~>"
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: '2.0'
|
169
169
|
description: Event sourcing gem
|
@@ -175,12 +175,12 @@ executables: []
|
|
175
175
|
extensions: []
|
176
176
|
extra_rdoc_files: []
|
177
177
|
files:
|
178
|
-
- .autotest
|
179
|
-
- .gitignore
|
180
|
-
- .rspec
|
181
|
-
- .ruby-gemset
|
182
|
-
- .ruby-version
|
183
|
-
- .travis.yml
|
178
|
+
- ".autotest"
|
179
|
+
- ".gitignore"
|
180
|
+
- ".rspec"
|
181
|
+
- ".ruby-gemset"
|
182
|
+
- ".ruby-version"
|
183
|
+
- ".travis.yml"
|
184
184
|
- Gemfile
|
185
185
|
- Gemfile.lock
|
186
186
|
- Gemfile.lock.old
|
@@ -225,17 +225,17 @@ require_paths:
|
|
225
225
|
- lib
|
226
226
|
required_ruby_version: !ruby/object:Gem::Requirement
|
227
227
|
requirements:
|
228
|
-
- -
|
228
|
+
- - ">="
|
229
229
|
- !ruby/object:Gem::Version
|
230
230
|
version: '2.0'
|
231
231
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
232
|
requirements:
|
233
|
-
- -
|
233
|
+
- - ">="
|
234
234
|
- !ruby/object:Gem::Version
|
235
235
|
version: '0'
|
236
236
|
requirements: []
|
237
237
|
rubyforge_project:
|
238
|
-
rubygems_version: 2.
|
238
|
+
rubygems_version: 2.4.3
|
239
239
|
signing_key:
|
240
240
|
specification_version: 4
|
241
241
|
summary: Event sourcing gem
|