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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 408485e918627490910f920486837c0c510d5a0e
4
- data.tar.gz: 29465f58b251b03282354035a6e9d1b1a3aedbd5
3
+ metadata.gz: 8f07f4c662a87341402536914257548434f11118
4
+ data.tar.gz: f3e4d1fbc6080b8eae3943b40c599fb9080673be
5
5
  SHA512:
6
- metadata.gz: 19f20a16e354b861fa4bd92056d8cff60b03c1826286e839f8b9ac7f5b67919405c0ad93e706c9d02efb82ef88add6ca7fe086e235a1e408d4cb33159bedd720
7
- data.tar.gz: 6cd4a5a6c1e14f0b9db9f192c92590041942918f255c9be722425553aff3c206c8b7c0ab5c2937e2758a27877b08842975a744b98aaf210a357c7e858aef148e
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
 
@@ -1,3 +1,3 @@
1
1
  module Eventus
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -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.0
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-21 00:00:00.000000000 Z
11
+ date: 2014-04-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An Event Store
14
14
  email: