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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f071fa32e56d2d2754f6ea625d16f5157d672039f605c62d45f06c41c0e9743
4
- data.tar.gz: 41e90b5b50d95eddc723e1290638a10cb05a50c49aaf996ea75d4547552d74b7
3
+ metadata.gz: d4575519de291e09a6f02085a07daeb09818edc01a5d8895204d443fc03db6b9
4
+ data.tar.gz: ce27f46beb087f7bcd48b6d5e690db1239e75adaffdcb524b1c24df0cbeea49f
5
5
  SHA512:
6
- metadata.gz: 352fbec15f059e0401c1e8b0ec99fb07c1abbc3a9ab7da827fba24c60fb947448bca41a3bfe933b88dd815d7173167db1ab17589fa938d96c0038c37a3dd3daa
7
- data.tar.gz: 79bf9b0ba01989b8e7b3da3af6a98cb5a6ea4cab703155e1965acbae7baecb421fba71693a901bdcef6258250bb7fa4881a4d9e4e896c5dea6e1075e833cc2e1
6
+ metadata.gz: de737107e012f7a07b5aea26280b425a6db374e13325054344e7c9fac196ee98bde2dbcc7d231fc0cd28b26992d805188a06d727373ef7c46e3552598c9c6e52
7
+ data.tar.gz: a624bb070c990b68b0a436d07c940f656238a244a80bfe2c789f3bb7feb4f8de0e66c65696496d75b936557e5bb4465466cd1e5f05f1b4583e8cf3bab3cc31ee
@@ -1,7 +1,7 @@
1
1
  module EntityStore
2
2
  class NotFound < StandardError
3
- def initialise(id)
3
+ def initialize(id)
4
4
  super("no item with id #{id} could be found")
5
5
  end
6
6
  end
7
- end
7
+ end
@@ -40,8 +40,10 @@ module EntityStore
40
40
  entity.id = storage_client.add_entity(entity)
41
41
  end
42
42
 
43
- add_events(entity) do
44
- snapshot_entity(entity) if entity.snapshot_due?
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
@@ -1,3 +1,3 @@
1
1
  module EntityStore
2
- VERSION = "1.4.0".freeze
2
+ VERSION = "1.5.0".freeze
3
3
  end
@@ -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, "Do not know how to create DummyEntity from Fixnum")
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).and_yield
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.0
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: 2018-11-21 00:00:00.000000000 Z
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
- rubyforge_project:
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