eventus 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eventus/persistence/mongo.rb +8 -3
- data/lib/eventus/version.rb +1 -1
- data/spec/persistence/mongo_spec.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f07f4c662a87341402536914257548434f11118
|
4
|
+
data.tar.gz: f3e4d1fbc6080b8eae3943b40c599fb9080673be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d348c4ef193bb481caa262b28725be1081bb140d23870dc08ee73167a730627cf94e1d53cffdc9a28339f8fe7e2773e984d69fa12e69bef9ec81ca701167316a
|
7
|
+
data.tar.gz: 0c5ed83d2c4c963c9b636ca431c29d03e86e1f9f7586b22f08a8e9cca3c87a740d969fc1b758738f05ef7ea29e08ab422ceefb52db18406ae0a5267cce6bfad2
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'mongo'
|
2
|
-
|
3
1
|
module Eventus
|
4
2
|
module Persistence
|
5
3
|
class Mongo
|
@@ -10,6 +8,7 @@ module Eventus
|
|
10
8
|
@commits = collection
|
11
9
|
@commits.ensure_index :sid => ::Mongo::ASCENDING
|
12
10
|
@commits.ensure_index :sid => ::Mongo::ASCENDING, :min => ::Mongo::ASCENDING
|
11
|
+
@commits.ensure_index :sid => ::Mongo::ASCENDING, :max => ::Mongo::DESCENDING
|
13
12
|
end
|
14
13
|
|
15
14
|
def commit(events)
|
@@ -35,7 +34,7 @@ module Eventus
|
|
35
34
|
doc
|
36
35
|
end
|
37
36
|
|
38
|
-
def load(id, min = nil)
|
37
|
+
def load(id, min = nil, max = nil)
|
39
38
|
Eventus.logger.debug "Loading stream: #{id}"
|
40
39
|
query = {sid:id}
|
41
40
|
|
@@ -43,12 +42,18 @@ module Eventus
|
|
43
42
|
query[:max] = {:$gte => min}
|
44
43
|
end
|
45
44
|
|
45
|
+
if max
|
46
|
+
query[:min] = {:$lte => max}
|
47
|
+
end
|
48
|
+
|
46
49
|
min ||= 0
|
50
|
+
max ||= Float::INFINITY
|
47
51
|
|
48
52
|
@commits.find(query).to_a
|
49
53
|
.map{|c| c['events']}
|
50
54
|
.flatten
|
51
55
|
.reject{|e| e['sequence'] < min}
|
56
|
+
.reject{|e| e['sequence'] > max}
|
52
57
|
.sort_by{|e| e['sequence']}
|
53
58
|
end
|
54
59
|
|
data/lib/eventus/version.rb
CHANGED
@@ -46,6 +46,11 @@ describe Eventus::Persistence::Mongo do
|
|
46
46
|
indexes.any? { |_,v| v['key'] == {'sid' => 1, 'min' => 1} }.should == true
|
47
47
|
end
|
48
48
|
|
49
|
+
it "should create an index on sid, max" do
|
50
|
+
indexes = persistence.commits.index_information
|
51
|
+
indexes.any? { |_,v| v['key'] == {'sid' => 1, 'max' => -1} }.should == true
|
52
|
+
end
|
53
|
+
|
49
54
|
describe "when events exist" do
|
50
55
|
let(:id) { uuid.generate :compact }
|
51
56
|
let(:events) { create_commit(id, 1, *(1..5)) }
|
@@ -86,6 +91,11 @@ describe Eventus::Persistence::Mongo do
|
|
86
91
|
result = persistence.load id, 3
|
87
92
|
result.should == events.select {|e| e['sequence'] >= 3}
|
88
93
|
end
|
94
|
+
|
95
|
+
it "should load all events up to a maxium" do
|
96
|
+
result = persistence.load id, nil, 2
|
97
|
+
result.should == events.select {|e| e['sequence'] <= 2}
|
98
|
+
end
|
89
99
|
end
|
90
100
|
|
91
101
|
it 'should return nil if there are no events' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Staten
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: An Event Store
|
14
14
|
email:
|