captainu-tincan 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tincan/message.rb +3 -1
- data/lib/tincan/sender.rb +1 -1
- data/lib/tincan/version.rb +1 -1
- data/spec/sender_spec.rb +8 -9
- 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: 81b4ca24c5fc0416c16995f2b9ceeb774d4e1fec
|
4
|
+
data.tar.gz: 5b685303cb058bc07739d6ab76992dcf543c6457
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0a21eec95dae01fad91ecfb7f21cbf4b0952b91c8a6a0c3a67394660f5a6a2e1f77b0e4a94ade22c88d41d5f1a1f0a5e3983845b5cb893202727b1a06879a68
|
7
|
+
data.tar.gz: 38c722a480c7a98c17c9835489c307df19a55d8e10a6467c47d1b445911df1f5e17f12dafb70ff01339812cbb5fb928fe566d96e0a6b807ccf0e38f5de61b4ff
|
data/lib/tincan/message.rb
CHANGED
@@ -6,7 +6,8 @@ module Tincan
|
|
6
6
|
# Encapsulates a message published to (and received from) a Redis "tincan"
|
7
7
|
# queue.
|
8
8
|
class Message
|
9
|
-
attr_accessor :object_name, :change_type, :object_data, :published_at
|
9
|
+
attr_accessor :object_name, :change_type, :object_data, :published_at,
|
10
|
+
:message_id
|
10
11
|
|
11
12
|
# Creates a new instance of a notification with an object (usually an
|
12
13
|
# ActiveModel instance).
|
@@ -15,6 +16,7 @@ module Tincan
|
|
15
16
|
def initialize
|
16
17
|
yield self if block_given?
|
17
18
|
self.published_at ||= DateTime.now
|
19
|
+
self.message_id ||= SecureRandom.uuid
|
18
20
|
end
|
19
21
|
|
20
22
|
# Deserializes an object from a JSON string.
|
data/lib/tincan/sender.rb
CHANGED
@@ -83,7 +83,7 @@ module Tincan
|
|
83
83
|
# unique identifier.
|
84
84
|
# @return [Integer] A unique identifier number for the message.
|
85
85
|
def identifier_for_message(message)
|
86
|
-
message.
|
86
|
+
message.message_id
|
87
87
|
end
|
88
88
|
|
89
89
|
# Generates a key to be used as the primary destination key in Redis.
|
data/lib/tincan/version.rb
CHANGED
data/spec/sender_spec.rb
CHANGED
@@ -98,23 +98,22 @@ describe Tincan::Sender do
|
|
98
98
|
context 'posting to all clients' do
|
99
99
|
before do
|
100
100
|
sender.publish(message)
|
101
|
-
@timestamp = Time.now.to_i
|
102
101
|
end
|
103
102
|
|
104
103
|
it 'publishes a message to Redis at a specific key' do
|
105
|
-
|
106
|
-
expect(
|
104
|
+
r_message = redis.get("data:dummy_class:messages:#{message.message_id}")
|
105
|
+
expect(r_message).to be_a(String)
|
107
106
|
expected = '{"object_name":"dummy_class","change_type":"create",'
|
108
107
|
expected += '"object_data":{"name":"Some Idiot"},"published_at":'
|
109
|
-
expect(
|
108
|
+
expect(r_message).to start_with(expected)
|
110
109
|
end
|
111
110
|
|
112
111
|
it 'also publishes a message ID to client-specific receiver lists' do
|
113
112
|
identifier = redis.lpop('data:dummy_class:some_client:messages')
|
114
|
-
expect(identifier).to eq(
|
113
|
+
expect(identifier).to eq(message.message_id)
|
115
114
|
|
116
115
|
identifier = redis.lpop('data:dummy_class:bork:messages')
|
117
|
-
expect(identifier).to eq(
|
116
|
+
expect(identifier).to eq(message.message_id.to_s)
|
118
117
|
end
|
119
118
|
end
|
120
119
|
|
@@ -126,7 +125,7 @@ describe Tincan::Sender do
|
|
126
125
|
|
127
126
|
it 'publishes message IDs to client-specific receivers, non-excluded' do
|
128
127
|
identifier = redis.lpop('data:dummy_class:some_client:messages')
|
129
|
-
expect(identifier).to eq(
|
128
|
+
expect(identifier).to eq(message.message_id)
|
130
129
|
|
131
130
|
identifier = redis.lpop('data:dummy_class:bork:messages')
|
132
131
|
expect(identifier).to be_nil
|
@@ -138,13 +137,13 @@ describe Tincan::Sender do
|
|
138
137
|
describe :formatting_helper_methods do
|
139
138
|
describe :identifier_for_message do
|
140
139
|
it 'generates a timestamp from the passed-in message' do
|
141
|
-
expect(sender.identifier_for_message(message)).to eq(
|
140
|
+
expect(sender.identifier_for_message(message)).to eq(message.message_id)
|
142
141
|
end
|
143
142
|
end
|
144
143
|
|
145
144
|
describe :primary_key_for_message do
|
146
145
|
it 'joins namespace, object name, and more to create a unique key' do
|
147
|
-
expected =
|
146
|
+
expected = "data:dummy_class:messages:#{message.message_id}"
|
148
147
|
expect(sender.primary_key_for_message(message)).to eq(expected)
|
149
148
|
end
|
150
149
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: captainu-tincan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Kreeger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|