event-sourcing 0.3.1.pre → 0.4.1.pre
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/event_sourcing/active_record/event.rb +15 -0
- data/lib/event_sourcing/event.rb +15 -7
- data/lib/event_sourcing/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e7e9d84d5ab139a65865e3ae8040b45010948ec302cdd227259416214953a61
|
4
|
+
data.tar.gz: 55708ccdde4471fe88a6115e9b93601aaa812a131be6e6630b64388051dd8d3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ffa246384995f7573f6b648119e15a3ef0c10b9eb89f35e32a75142d0f9f4533225e6ebc0c99c2ccc2a42b755b672d1b099c1ca5e145bc973656e6fec79ab88
|
7
|
+
data.tar.gz: c2787e85a62233a404eb461e890e30088c7652d681b8828b9dc1d3e26a45b480f3fe507ad6c5c46c40da6b3b1367debf7a4e4b1ebe78aff783946e6cb4c7d0d0
|
@@ -80,6 +80,21 @@ module EventSourcing
|
|
80
80
|
|
81
81
|
save!
|
82
82
|
end
|
83
|
+
|
84
|
+
# Creates a "nested transaction", forcing a SAVEPOINT in case the event persistence is
|
85
|
+
# called inside an `ActiveRecord#transaction` block
|
86
|
+
def persistence_wrapper
|
87
|
+
::ActiveRecord::Base.transaction(requires_new: true) do
|
88
|
+
yield
|
89
|
+
end
|
90
|
+
|
91
|
+
# @return [Class] Given class from metadata[:klass]
|
92
|
+
# Materializes the event class from the database
|
93
|
+
def reify
|
94
|
+
event_class = Object.const_get(metadata[:klass])
|
95
|
+
event_class.find(self[:id])
|
96
|
+
end
|
97
|
+
end
|
83
98
|
end
|
84
99
|
end
|
85
100
|
end
|
data/lib/event_sourcing/event.rb
CHANGED
@@ -105,16 +105,24 @@ module EventSourcing
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def persist_and_dispatch
|
108
|
-
|
108
|
+
persistence_wrapper do
|
109
|
+
self.aggregate = build_aggregate
|
109
110
|
|
110
|
-
|
111
|
-
|
111
|
+
# Apply
|
112
|
+
self.aggregate = apply(aggregate)
|
112
113
|
|
113
|
-
|
114
|
-
|
115
|
-
|
114
|
+
# Persist aggregate
|
115
|
+
persist_aggregate
|
116
|
+
persist_event
|
116
117
|
|
117
|
-
|
118
|
+
dispatch
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Customizable persistence wrapper for the event persistence and dispatch method
|
123
|
+
# Allows to wrap aggregate and event persistence into a transaction
|
124
|
+
def persistence_wrapper
|
125
|
+
yield
|
118
126
|
end
|
119
127
|
|
120
128
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event-sourcing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Conversation Dev Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|