entity_store 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/entity_store/not_found.rb +2 -2
- data/lib/entity_store/store.rb +5 -6
- data/lib/entity_store/version.rb +1 -1
- data/spec/entity_store/entity_spec.rb +1 -1
- data/spec/entity_store/store_spec.rb +17 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4575519de291e09a6f02085a07daeb09818edc01a5d8895204d443fc03db6b9
|
4
|
+
data.tar.gz: ce27f46beb087f7bcd48b6d5e690db1239e75adaffdcb524b1c24df0cbeea49f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de737107e012f7a07b5aea26280b425a6db374e13325054344e7c9fac196ee98bde2dbcc7d231fc0cd28b26992d805188a06d727373ef7c46e3552598c9c6e52
|
7
|
+
data.tar.gz: a624bb070c990b68b0a436d07c940f656238a244a80bfe2c789f3bb7feb4f8de0e66c65696496d75b936557e5bb4465466cd1e5f05f1b4583e8cf3bab3cc31ee
|
data/lib/entity_store/store.rb
CHANGED
@@ -40,8 +40,10 @@ module EntityStore
|
|
40
40
|
entity.id = storage_client.add_entity(entity)
|
41
41
|
end
|
42
42
|
|
43
|
-
add_events(entity)
|
44
|
-
|
43
|
+
added_events = add_events(entity)
|
44
|
+
|
45
|
+
if entity.snapshot_due? || added_events >= Config.snapshot_threshold
|
46
|
+
snapshot_entity(entity)
|
45
47
|
end
|
46
48
|
|
47
49
|
# publish version increment signal event to the bus
|
@@ -105,11 +107,10 @@ module EntityStore
|
|
105
107
|
end
|
106
108
|
storage_client.add_events(items)
|
107
109
|
|
108
|
-
yield if block_given?
|
109
|
-
|
110
110
|
items.each { |e| event_bus.publish(entity.type, e) }
|
111
111
|
|
112
112
|
entity.clear_pending_events
|
113
|
+
items.count
|
113
114
|
end
|
114
115
|
|
115
116
|
def upsert_events(entity)
|
@@ -121,8 +122,6 @@ module EntityStore
|
|
121
122
|
|
122
123
|
filtered_items = storage_client.upsert_events(items)
|
123
124
|
|
124
|
-
yield if block_given?
|
125
|
-
|
126
125
|
filtered_items.each { |e| event_bus.publish(entity.type, e) }
|
127
126
|
|
128
127
|
entity.clear_pending_events
|
data/lib/entity_store/version.rb
CHANGED
@@ -84,7 +84,7 @@ describe Entity do
|
|
84
84
|
subject { DummyEntity.new(1) }
|
85
85
|
|
86
86
|
it "should raise a readable error" do
|
87
|
-
expect { subject }.to raise_error(RuntimeError,
|
87
|
+
expect { subject }.to raise_error(RuntimeError, /\ADo not know how to create DummyEntity from (Integer|Fixnum)\z/)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -114,7 +114,7 @@ describe Store do
|
|
114
114
|
@entity = DummyEntityForStore.new(:id => random_string)
|
115
115
|
@storage_client = double("StorageClient", :save_entity => true)
|
116
116
|
@store = Store.new
|
117
|
-
@store.stub(:add_events).
|
117
|
+
@store.stub(:add_events) { |entity| entity.pending_events.count }
|
118
118
|
@store.stub(:storage_client) { @storage_client }
|
119
119
|
@entity.stub(:pending_events) { [ double('Event') ] }
|
120
120
|
end
|
@@ -194,8 +194,23 @@ describe Store do
|
|
194
194
|
subject
|
195
195
|
end
|
196
196
|
end
|
197
|
-
end
|
198
197
|
|
198
|
+
context "when flushed events exceeds snapshotting threshold" do
|
199
|
+
before(:each) do
|
200
|
+
@entity.version = 1
|
201
|
+
@entity.stub(:pending_events) do
|
202
|
+
(1..EntityStore::Config.snapshot_threshold).map do
|
203
|
+
double('Event')
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should snapshot the entity" do
|
209
|
+
@storage_client.should_receive(:snapshot_entity).with(@entity)
|
210
|
+
subject
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
199
214
|
end
|
200
215
|
|
201
216
|
describe "getters" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: entity_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Bird
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bson
|
@@ -86,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
|
-
|
90
|
-
rubygems_version: 2.7.7
|
89
|
+
rubygems_version: 3.2.33
|
91
90
|
signing_key:
|
92
91
|
specification_version: 4
|
93
92
|
summary: Event sourced entity store with a replaceable body
|