alephant-sequencer 0.0.3 → 0.0.4

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: 947e5d4a40ae350a53bd3fad90116c69bb0b4ce7
4
- data.tar.gz: ca73e140db5a1411605ddb4b79a8856947ae2d04
3
+ metadata.gz: c9469dfac1eb96f8c9386bf691836cf8f3017f59
4
+ data.tar.gz: c97554d0a0b758413c9024f4ee4d2fd5f9167faf
5
5
  SHA512:
6
- metadata.gz: 9b58d7f6b72dfa3951a5385ba770d28c9ef8800f7500b338c931dad26bb4faa1dfc4d6313145e39c03af5fe35907c8a024e4e89650aeaddf9d92cde0d5319be0
7
- data.tar.gz: 8a6744b263a2265b4f44b53356ae45e5f34e5ed3aa77df9b69b60418a3c0cccad21ba0cdb0420b5546f3eef6c95d52b8d8c68008abcaf4fc2199773944dd9a09
6
+ metadata.gz: 10ef0ab3836211d83e502690620f7d38b10c44761dd99abe9b43f47eca517de9908b54b971c3287ffecef54ef9b693c03837489e6a422e427d74d86d5c16b0c4
7
+ data.tar.gz: be84f7081d5ab556ee69fe5fd96d6adb5db862e69ca6ea5b387db3b9915f812bde4df8e9dc5cf6c11fc96e1a2cbf6bb09f83fbe2c39ca4430b87525c525737f4
@@ -7,7 +7,7 @@ module Alephant
7
7
  include ::Alephant::Logger
8
8
  attr_reader :ident, :jsonpath
9
9
 
10
- def initialize(sequence_table, id, sequence_path = nil)
10
+ def initialize(sequence_table, id, sequence_path)
11
11
  @mutex = Mutex.new
12
12
  @sequence_table = sequence_table
13
13
  @jsonpath = sequence_path
@@ -16,8 +16,8 @@ module Alephant
16
16
  @sequence_table.create
17
17
  end
18
18
 
19
- def sequential?(data)
20
- get_last_seen < sequence_id_from(data)
19
+ def sequential?(msg)
20
+ get_last_seen < sequence_id_from(msg)
21
21
  end
22
22
 
23
23
  def delete!
@@ -25,8 +25,8 @@ module Alephant
25
25
  @sequence_table.delete_item!(ident)
26
26
  end
27
27
 
28
- def set_last_seen(data)
29
- last_seen_id = sequence_id_from(data)
28
+ def set_last_seen(msg)
29
+ last_seen_id = sequence_id_from(msg)
30
30
  logger.info("Sequencer.set_last_seen: #{last_seen_id}")
31
31
 
32
32
  @sequence_table.set_sequence_for(ident, last_seen_id)
@@ -36,21 +36,9 @@ module Alephant
36
36
  @sequence_table.sequence_for(ident)
37
37
  end
38
38
 
39
- private
40
- def sequence_id_from(data)
41
- jsonpath.nil? ?
42
- default_sequence_id_for(data) :
43
- sequence_from_jsonpath_for(data)
39
+ def sequence_id_from(msg)
40
+ JsonPath.on(msg.body, jsonpath).first
44
41
  end
45
-
46
- def sequence_from_jsonpath_for(data)
47
- JsonPath.on(data.body, jsonpath).first
48
- end
49
-
50
- def default_sequence_id_for(data)
51
- data.body['sequence_id'].to_i
52
- end
53
-
54
42
  end
55
43
  end
56
44
  end
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Sequencer
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -38,7 +38,7 @@ describe Alephant::Sequencer do
38
38
  table.should_receive(:sequence_for).with(ident).and_return(:expected_value)
39
39
 
40
40
  expect(
41
- Alephant::Sequencer::Sequencer.new(table, ident).get_last_seen
41
+ Alephant::Sequencer::Sequencer.new(table, ident, jsonpath).get_last_seen
42
42
  ).to eq(:expected_value)
43
43
  end
44
44
  end
@@ -53,7 +53,15 @@ describe Alephant::Sequencer do
53
53
  table.stub(:create)
54
54
  table.should_receive(:set_sequence_for).with(ident, last_seen)
55
55
 
56
- Alephant::Sequencer::Sequencer.new(table, ident).set_last_seen(data)
56
+ Alephant::Sequencer::Sequencer.new(table, ident, jsonpath).set_last_seen(data)
57
+ end
58
+ end
59
+
60
+ describe "#sequence_id_from(data)" do
61
+ subject { Alephant::Sequencer::Sequencer.new(sequence_table, ident, '$.set_sequence_id') }
62
+ it "should return the id described by the set jsonpath" do
63
+ msg = Struct.new(:body).new({ "set_sequence_id" => 1 })
64
+ expect(subject.sequence_id_from msg).to eq(1)
57
65
  end
58
66
  end
59
67
 
@@ -83,7 +91,7 @@ describe Alephant::Sequencer do
83
91
  end
84
92
 
85
93
  context "jsonpath = nil" do
86
- let(:jsonpath) { nil }
94
+ let(:jsonpath) { '$.sequence_id' }
87
95
  subject { Alephant::Sequencer::Sequencer.new(sequence_table, :ident, jsonpath) }
88
96
 
89
97
  context "sequential" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-sequencer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Kenny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-13 00:00:00.000000000 Z
11
+ date: 2014-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler