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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e92a9393acf371e129d94e8a789051dd8cc59748e0c27fd3ccf8f0256902c81
4
- data.tar.gz: 111bbcaa8311f65c21b46e7f02c1619b9bb1a62c52479001a51fb6fefcea76fd
3
+ metadata.gz: 8e7e9d84d5ab139a65865e3ae8040b45010948ec302cdd227259416214953a61
4
+ data.tar.gz: 55708ccdde4471fe88a6115e9b93601aaa812a131be6e6630b64388051dd8d3d
5
5
  SHA512:
6
- metadata.gz: ae806937271e3050069b46e8fd906c019bb2e879f582c4bd67aaf54548d080d430b82161c8d9e5d2655bbd6720dcb9767400d6045c263933c119f59b3ecf45de
7
- data.tar.gz: '094a01faafbc98176c346f2d893ddae1e2d8ce398291a8e5821b6d65e9633629816cca9a320ba236a993cbfd852061a65e25e95baca5227029d53bf04a365be3'
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
@@ -105,16 +105,24 @@ module EventSourcing
105
105
  end
106
106
 
107
107
  def persist_and_dispatch
108
- self.aggregate = build_aggregate
108
+ persistence_wrapper do
109
+ self.aggregate = build_aggregate
109
110
 
110
- # Apply
111
- self.aggregate = apply(aggregate)
111
+ # Apply
112
+ self.aggregate = apply(aggregate)
112
113
 
113
- # Persist aggregate
114
- persist_aggregate
115
- persist_event
114
+ # Persist aggregate
115
+ persist_aggregate
116
+ persist_event
116
117
 
117
- dispatch
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
@@ -1,3 +1,3 @@
1
1
  module EventSourcing
2
- VERSION = "0.3.1.pre"
2
+ VERSION = "0.4.1.pre"
3
3
  end
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.3.1.pre
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-22 00:00:00.000000000 Z
11
+ date: 2018-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler