alephant-sequencer 0.0.8 → 0.1.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: 0390458d47e5ab213103d386505b95893d3b22ff
4
- data.tar.gz: 6233dd2447347b73b0cb62349aa28fa3c6f74a3d
3
+ metadata.gz: 3daf0b16c8239ed84c8714bdfd2ab292c65dcf14
4
+ data.tar.gz: 7fd66428f588bcc53a8806994bb768ef8720e16d
5
5
  SHA512:
6
- metadata.gz: b587d839b93e7eca666ca6e947e8d5c941331b582d0629bf92fe541dab39c899dd9494d65c3c57e214e0c43dc6a374609039dd4fc7ff782da8ef17444ad5e5ed
7
- data.tar.gz: 6b54e05af1e9997358adbe0abf83010f9701da8781310578bbb8df75a113dd3d962186e810e8380d05c4fdabbffdb323623b1e1ec0f76e8fae6a428d8e12c2cd
6
+ metadata.gz: 1a35be4e9cd3f355923a65b8e59880ae9480826ab0062fc8d67b00bd1e7109b478006dfeee0634aeb6f45e2b450ad0a05988d79117859c919ffbfff65024f669
7
+ data.tar.gz: 76c2983a853d1e2146a50bc52f1a9767099539aafc9a29718a9639be0a59a6d47f76a2f48c80b533434769a9870a9ab3477d3996b304856e9cb47cefbf6749ca
@@ -5,16 +5,17 @@ require 'alephant/logger'
5
5
  module Alephant
6
6
  module Sequencer
7
7
  class Sequencer
8
- include ::Alephant::Logger
9
- attr_reader :ident, :jsonpath
8
+ include Logger
9
+ attr_reader :ident, :jsonpath, :keep_all
10
10
 
11
- def initialize(sequence_table, id, sequence_path)
11
+ def initialize(sequence_table, id, sequence_path, keep_all = true)
12
12
  @sequence_table = sequence_table
13
13
  @sequence_table.create
14
14
 
15
- @exists = exists?
15
+ @keep_all = keep_all
16
+ @exists = exists?
16
17
  @jsonpath = sequence_path
17
- @ident = id
18
+ @ident = id
18
19
  end
19
20
 
20
21
  def sequential?(msg)
@@ -26,10 +27,12 @@ module Alephant
26
27
  end
27
28
 
28
29
  def sequence(msg, &block)
29
- block.call(msg)
30
-
31
30
  last_seen_id = get_last_seen
32
- if (last_seen_id || 0) < Sequencer.sequence_id_from(msg, jsonpath)
31
+ sequential = ((last_seen_id || 0) < Sequencer.sequence_id_from(msg, jsonpath))
32
+
33
+ block.call(msg) if (sequential || keep_all)
34
+
35
+ if sequential
33
36
  set_last_seen(msg, last_seen_id)
34
37
  else
35
38
  logger.info("Sequencer#sequence nonsequential message for #{ident}")
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Sequencer
3
- VERSION = "0.0.8"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -54,6 +54,15 @@ describe Alephant::Sequencer do
54
54
  m
55
55
  end
56
56
 
57
+ let(:an_uncalled_proc) do
58
+ a_block = double()
59
+ a_block.should_not_receive(:called).with(message)
60
+
61
+ Proc.new do |msg|
62
+ a_block.called(msg)
63
+ end
64
+ end
65
+
57
66
  let(:a_proc) do
58
67
  a_block = double()
59
68
  a_block.should_receive(:called).with(message)
@@ -138,6 +147,19 @@ describe Alephant::Sequencer do
138
147
  subject = Alephant::Sequencer::Sequencer.new(sequence_table, ident, jsonpath)
139
148
  subject.sequence(message, &a_proc)
140
149
  end
150
+
151
+ context "keep_all is false" do
152
+ let(:keep_all) { false }
153
+ it "should not call the passed block with msg" do
154
+ subject = Alephant::Sequencer::Sequencer.new(
155
+ sequence_table,
156
+ ident,
157
+ jsonpath,
158
+ keep_all
159
+ )
160
+ subject.sequence(message, &an_uncalled_proc)
161
+ end
162
+ end
141
163
  end
142
164
 
143
165
  context "last_seen_id < sequence_id_from(msg)" 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.8
4
+ version: 0.1.0
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-04-02 00:00:00.000000000 Z
11
+ date: 2014-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler