philotic 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/philotic/message.rb +9 -2
- data/lib/philotic/version.rb +1 -1
- data/spec/philotic/message_spec.rb +104 -16
- data/spec/philotic/subscriber_spec.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 839559e1f390f9d5630b32dc07f3ed01c36156c5
|
4
|
+
data.tar.gz: 3e096414cf3ae1a59b30eeb9620a3832858dd44f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc124cc549906ae789b422d0fc65b6eb2575e0e349b420da051db9f6e387d534fa3450d36429871d41f6e88512e00e9563404b933f01dbc3818fd1688edeccc0
|
7
|
+
data.tar.gz: 69108c3e0b3d30839f61ffdd2c8bf6bf32ef8878e6781605b73eba9c0fc359dd990d3caca074ad7a59400bb8af52b54e502075d1f51361d68af6300445a476e3
|
data/lib/philotic/message.rb
CHANGED
@@ -3,6 +3,7 @@ require 'philotic/singleton'
|
|
3
3
|
|
4
4
|
module Philotic
|
5
5
|
class Message
|
6
|
+
NotInstantiableError = Class.new(RuntimeError)
|
6
7
|
|
7
8
|
attr_accessor :connection, :publish_error, :delivery_info
|
8
9
|
attr_writer :published
|
@@ -28,6 +29,7 @@ module Philotic
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def initialize(routables={}, payloads={}, connection=nil)
|
32
|
+
raise NotInstantiableError if self.class == Philotic::Message
|
31
33
|
self.timestamp = Time.now.to_i
|
32
34
|
self.philotic_firehose = true
|
33
35
|
self.connection = connection
|
@@ -71,7 +73,8 @@ module Philotic
|
|
71
73
|
end
|
72
74
|
|
73
75
|
def self.publish(*args)
|
74
|
-
self.new(
|
76
|
+
message_class = self == Philotic::Message ? Class.new(self) : self
|
77
|
+
message_class.new(*args).publish
|
75
78
|
end
|
76
79
|
|
77
80
|
def delivery_tag
|
@@ -101,6 +104,10 @@ module Philotic
|
|
101
104
|
|
102
105
|
private
|
103
106
|
|
107
|
+
def _is_anonymous_message?
|
108
|
+
self.is_a?(Philotic::Message) && self.class.name.nil?
|
109
|
+
end
|
110
|
+
|
104
111
|
def _payload_or_headers(payload_or_headers)
|
105
112
|
attribute_hash = {}
|
106
113
|
self.class.send("attr_#{payload_or_headers}_accessors").each do |attr|
|
@@ -114,7 +121,7 @@ module Philotic
|
|
114
121
|
attrs.each do |key, value|
|
115
122
|
if self.respond_to?(:"#{key}=")
|
116
123
|
send(:"#{key}=", value)
|
117
|
-
elsif
|
124
|
+
elsif _is_anonymous_message?
|
118
125
|
_set_message_attribute(type, key, value)
|
119
126
|
end
|
120
127
|
end
|
data/lib/philotic/version.rb
CHANGED
@@ -11,6 +11,11 @@ class TestEvent < TestEventParent
|
|
11
11
|
end
|
12
12
|
|
13
13
|
describe Philotic::Message do
|
14
|
+
|
15
|
+
it 'is not instantiable' do
|
16
|
+
expect { Philotic::Message.new }.to raise_error(Philotic::Message::NotInstantiableError)
|
17
|
+
end
|
18
|
+
|
14
19
|
let(:message) { TestEvent.new }
|
15
20
|
subject { message }
|
16
21
|
|
@@ -39,15 +44,6 @@ describe Philotic::Message do
|
|
39
44
|
expect(subject.metadata.keys).to eq([:timestamp])
|
40
45
|
end
|
41
46
|
|
42
|
-
context 'overriding a value with metadata=' do
|
43
|
-
before do
|
44
|
-
subject.metadata = {mandatory: false}
|
45
|
-
end
|
46
|
-
it 'should work' do
|
47
|
-
expect(subject.metadata).to include({mandatory: false})
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
47
|
Philotic::Message.methods.sort.each do |method_name|
|
52
48
|
specify { expect(subject.class.methods).to include method_name.to_sym }
|
53
49
|
end
|
@@ -63,6 +59,16 @@ describe Philotic::Message do
|
|
63
59
|
end
|
64
60
|
|
65
61
|
describe 'metadata' do
|
62
|
+
|
63
|
+
context 'overriding a value with metadata=' do
|
64
|
+
before do
|
65
|
+
subject.metadata = {mandatory: false}
|
66
|
+
end
|
67
|
+
it 'should work' do
|
68
|
+
expect(subject.metadata).to include({mandatory: false})
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
66
72
|
it 'should have a timestamp' do
|
67
73
|
Timecop.freeze
|
68
74
|
expect(subject.metadata).to eq(timestamp: Time.now.to_i)
|
@@ -80,7 +86,7 @@ describe Philotic::Message do
|
|
80
86
|
end
|
81
87
|
end
|
82
88
|
|
83
|
-
|
89
|
+
describe 'generic messages' do
|
84
90
|
let(:headers) do
|
85
91
|
{
|
86
92
|
header1: 'h1',
|
@@ -96,23 +102,105 @@ describe Philotic::Message do
|
|
96
102
|
payload3: 'h3',
|
97
103
|
}
|
98
104
|
end
|
99
|
-
it 'builds an message with dynamic headers and payloads' do
|
100
|
-
message = Philotic::Message.new(headers, payloads)
|
101
105
|
|
102
|
-
|
103
|
-
|
106
|
+
describe 'publishing messages' do
|
107
|
+
let(:message_1_headers) { {message_1_header_1: 1, message_1_header_2: 2} }
|
108
|
+
let(:message_1_payload) { {message_1_payload_1: 1, message_1_payload_2: 2} }
|
109
|
+
|
110
|
+
let(:message_2_headers) { {message_2_header_1: 1, message_2_header_2: 2} }
|
111
|
+
let(:message_2_payload) { {message_2_payload_1: 1, message_2_payload_2: 2} }
|
112
|
+
|
113
|
+
it 'builds the proper routable accessors' do
|
114
|
+
expect(Philotic.connection).to receive(:publish) do |message|
|
115
|
+
expect(message.class.attr_routable_accessors).to include(*message_1_headers.keys)
|
116
|
+
end
|
117
|
+
Philotic::Message.publish message_1_headers, message_1_payload
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'builds the proper payload accessors' do
|
121
|
+
expect(Philotic.connection).to receive(:publish) do |message|
|
122
|
+
expect(message.class.attr_payload_accessors).to include(*message_1_payload.keys)
|
123
|
+
end
|
124
|
+
Philotic::Message.publish message_1_headers, message_1_payload
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'builds the proper headers' do
|
128
|
+
expect(Philotic.connection).to receive(:publish) do |message|
|
129
|
+
expect(message.headers).to include(message_1_headers)
|
130
|
+
end
|
131
|
+
Philotic::Message.publish message_1_headers, message_1_payload
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'builds the proper payload' do
|
135
|
+
expect(Philotic.connection).to receive(:publish) do |message|
|
136
|
+
expect(message.payload).to include(message_1_payload)
|
137
|
+
end
|
138
|
+
Philotic::Message.publish message_1_headers, message_1_payload
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'in succession' do
|
142
|
+
it 'builds the proper routable accessors on succesive calls' do
|
143
|
+
allow(Philotic.connection).to receive(:publish)
|
144
|
+
Philotic::Message.publish message_1_headers, message_1_payload
|
145
|
+
|
146
|
+
expect(Philotic.connection).to receive(:publish) do |message|
|
147
|
+
expect(message.class.attr_routable_accessors).not_to include(*message_1_headers.keys)
|
148
|
+
expect(message.class.attr_routable_accessors).to include(*message_2_headers.keys)
|
149
|
+
end
|
150
|
+
|
151
|
+
Philotic::Message.publish message_2_headers, message_2_payload
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'builds the proper payload accessors on succesive calls' do
|
156
|
+
allow(Philotic.connection).to receive(:publish)
|
157
|
+
Philotic::Message.publish message_1_headers, message_1_payload
|
158
|
+
|
159
|
+
expect(Philotic.connection).to receive(:publish) do |message|
|
160
|
+
expect(message.class.attr_payload_accessors).not_to include(*message_1_payload.keys)
|
161
|
+
expect(message.class.attr_payload_accessors).to include(*message_2_payload.keys)
|
162
|
+
end
|
163
|
+
|
164
|
+
Philotic::Message.publish message_2_headers, message_2_payload
|
165
|
+
|
166
|
+
end
|
104
167
|
|
168
|
+
it 'builds the proper headers on succesive calls' do
|
169
|
+
allow(Philotic.connection).to receive(:publish)
|
170
|
+
Philotic::Message.publish message_1_headers, message_1_payload
|
171
|
+
|
172
|
+
expect(Philotic.connection).to receive(:publish) do |message|
|
173
|
+
expect(message.headers).not_to include(message_1_headers)
|
174
|
+
expect(message.headers).to include(message_2_headers)
|
175
|
+
end
|
176
|
+
|
177
|
+
Philotic::Message.publish message_2_headers, message_2_payload
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'builds the proper payload on succesive calls' do
|
182
|
+
allow(Philotic.connection).to receive(:publish)
|
183
|
+
Philotic::Message.publish message_1_headers, message_1_payload
|
184
|
+
|
185
|
+
expect(Philotic.connection).to receive(:publish) do |message|
|
186
|
+
expect(message.payload).not_to include(message_1_payload)
|
187
|
+
expect(message.payload).to include(message_2_payload)
|
188
|
+
end
|
189
|
+
|
190
|
+
Philotic::Message.publish message_2_headers, message_2_payload
|
191
|
+
|
192
|
+
end
|
193
|
+
end
|
105
194
|
end
|
106
195
|
end
|
107
196
|
|
108
197
|
describe '#publish' do
|
109
|
-
subject { Philotic::Message.new }
|
198
|
+
subject { Class.new(Philotic::Message).new }
|
110
199
|
specify do
|
111
200
|
expect(subject.connection).to receive(:publish).with(subject)
|
112
201
|
|
113
202
|
subject.publish
|
114
203
|
end
|
115
|
-
|
116
204
|
end
|
117
205
|
|
118
206
|
describe '.publish' do
|
@@ -92,7 +92,7 @@ describe Philotic::Subscriber do
|
|
92
92
|
let(:channel) { double }
|
93
93
|
let(:delivery_tag) { double }
|
94
94
|
let(:delivery_info) { double }
|
95
|
-
let(:message) { Philotic::Message.new }
|
95
|
+
let(:message) { Class.new(Philotic::Message).new }
|
96
96
|
subject { Philotic::Connection.new.subscriber }
|
97
97
|
|
98
98
|
specify do
|
@@ -108,7 +108,7 @@ describe Philotic::Subscriber do
|
|
108
108
|
let(:channel) { double }
|
109
109
|
let(:delivery_tag) { double }
|
110
110
|
let(:delivery_info) { double }
|
111
|
-
let(:message) { Philotic::Message.new }
|
111
|
+
let(:message) { Class.new(Philotic::Message).new }
|
112
112
|
subject { Philotic::Connection.new.subscriber }
|
113
113
|
|
114
114
|
specify do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: philotic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Keyes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codeclimate-test-reporter
|
@@ -252,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
252
252
|
version: '0'
|
253
253
|
requirements: []
|
254
254
|
rubyforge_project:
|
255
|
-
rubygems_version: 2.4.
|
255
|
+
rubygems_version: 2.4.8
|
256
256
|
signing_key:
|
257
257
|
specification_version: 4
|
258
258
|
summary: Lightweight, opinionated wrapper for using RabbitMQ headers exchanges
|