entity_store 0.3.9 → 0.4.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
  SHA1:
3
- metadata.gz: 09a2238ae22b823eb65cacce1f43a7f94733ab5f
4
- data.tar.gz: 6d18a742b0e7666363eeac9a4a51e282a90d635b
3
+ metadata.gz: 3b8ff1e612eb5f628787b5ffbbf7015761ab631b
4
+ data.tar.gz: 322df7d392825dcd88a5efc2c85caac55e41e6c1
5
5
  SHA512:
6
- metadata.gz: 238db945f6836367e0c73d5ffdd85886815928134dceb8ad8b50502590fee7d42680abc64b85b2206709cc2b8356054b54ce35a80892d5013af3ff0b36e557d4
7
- data.tar.gz: e737e0eb77949e522c6817382a6609394af432d47cf16638ec09ae90f0884cb1820f6384923b0fee0e1c9e14a4cf406c5ff46017c84f707321fc348f2e66f70b
6
+ metadata.gz: 8358d50054068df7040d96bb2559bc1fa5f63fef6fd31a3fb626151ff88b570c6ecdf623b3bd049bc0d2e562fd57ab2c436874c94f58eaeacd5ad1ac9b9a456c
7
+ data.tar.gz: 550dc6708c0d5a4acfbd5fe94a5529637c7b145ad948b5d0f041b7aef3a2fdceecb3fb1799fa9ce433310952b2ed27389fa041583220a9ddc272d2a1241cd7ed
@@ -32,9 +32,18 @@ module EntityStore
32
32
  end
33
33
 
34
34
  def version=(value)
35
+ @_snapshot_version = value unless @_snapshot_version
35
36
  @_version = value
36
37
  end
37
38
 
39
+ def snapshot_due?
40
+ if version % Config.snapshot_threshold == 0
41
+ true
42
+ else
43
+ @_snapshot_version and (version - @_snapshot_version) >= Config.snapshot_threshold
44
+ end
45
+ end
46
+
38
47
  def generate_version_incremented_event
39
48
  event_class= "#{self.class.name}VersionIncremented".split('::').inject(Object) {|obj, name| obj.const_get(name) }
40
49
  event_class.new(:entity_id => id, :version => version)
@@ -61,4 +70,4 @@ module EntityStore
61
70
  "<#{self.class.name} #{id} #{self.attributes.inspect}>"
62
71
  end
63
72
  end
64
- end
73
+ end
@@ -21,7 +21,9 @@ module EntityStore
21
21
 
22
22
  def save(entity)
23
23
  # need to look at concurrency if we start storing version on client
24
- unless entity.pending_events.empty?
24
+ if entity.pending_events.empty?
25
+ snapshot_entity(entity) if entity.snapshot_due?
26
+ else
25
27
  entity.version += 1
26
28
  if entity.id
27
29
  storage_client.save_entity(entity)
@@ -30,7 +32,7 @@ module EntityStore
30
32
  end
31
33
 
32
34
  add_events(entity) do
33
- snapshot_entity(entity) if entity.version % Config.snapshot_threshold == 0
35
+ snapshot_entity(entity) if entity.snapshot_due?
34
36
  end
35
37
 
36
38
  # publish version increment signal event to the bus
@@ -1,3 +1,3 @@
1
1
  module EntityStore
2
- VERSION = "0.3.9".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
@@ -79,7 +79,6 @@ describe Store do
79
79
  before(:each) do
80
80
  @new_id = random_string
81
81
  @entity = DummyEntityForStore.new(:id => random_string)
82
- @entity.version = random_integer * EntityStore::Config.snapshot_threshold
83
82
  @storage_client = double("StorageClient", :save_entity => true)
84
83
  @store = Store.new
85
84
  @store.stub(:add_events).and_yield
@@ -139,13 +138,28 @@ describe Store do
139
138
  end
140
139
 
141
140
  context "when entity version is commensurate with snapshotting" do
142
- before(:each) do
143
- @entity.version = random_integer * EntityStore::Config.snapshot_threshold - 1
141
+ context "due to modulus of snapshot_threshold" do
142
+ before(:each) do
143
+ @entity.version = random_integer * EntityStore::Config.snapshot_threshold - 1
144
+ end
145
+
146
+ it "should snapshot the entity" do
147
+ @storage_client.should_receive(:snapshot_entity).with(@entity)
148
+ subject
149
+ end
144
150
  end
145
151
 
146
- it "should snapshot the entity" do
147
- @storage_client.should_receive(:snapshot_entity).with(@entity)
148
- subject
152
+ context "due to more than snapshot_threshold versions having passed since last snapshot" do
153
+ before(:each) do
154
+ starting_version = random_integer
155
+ @entity.version = starting_version
156
+ @entity.version = starting_version + EntityStore::Config.snapshot_threshold + 1
157
+ end
158
+
159
+ it "should snapshot the entity" do
160
+ @storage_client.should_receive(:snapshot_entity).with(@entity)
161
+ subject
162
+ end
149
163
  end
150
164
  end
151
165
 
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: 0.3.9
4
+ version: 0.4.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: 2014-08-15 00:00:00.000000000 Z
11
+ date: 2015-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  requirements: []
108
108
  rubyforge_project:
109
- rubygems_version: 2.4.1
109
+ rubygems_version: 2.4.5
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Event sourced entity store with a replaceable body