sxs 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93243c7fda169668829a419181bbe7136e24ebbc9eb245108182995899abde7b
4
- data.tar.gz: f4e9b2f8eeb6c5f397405ad8badd7cd61a04e32f44ac9cc7625799c2bcf14f66
3
+ metadata.gz: bfa20059cae54bb1425872b0ae8acc51acbc7666c9c3ae755a2746247271ed3d
4
+ data.tar.gz: f2558d38acc7d575503c5f383bc307d01d610c61e893b8c29c567f87cb27af3e
5
5
  SHA512:
6
- metadata.gz: 45059b39c7cf5f1ff0ccfd7e8526544c38934dd14cf5a6d20172e232d18a217691a4b4f6c764ff5165a5083999977d8139bca0bfafa5ec979c265ac77c1b8c7d
7
- data.tar.gz: d28d6de75c87dd17f251a8bf2a92da6f0f41acac2a65a2eaa4c5b58e7a8a127ad209e03c47378c8e2cc4bf737f03f3a1a325c4323f11acc03765886f32f1b81a
6
+ metadata.gz: 3ff293454db87415920ec4a06d6715f3ca0d71d5f125f1078f7a156fb74a80f1905311e1832983617d193ea1b94f5c00e830664f64347d5566e5b0aa448f85c3
7
+ data.tar.gz: 57291c8906e3583919286f6a829b1aec5f1ef62fab78fa623c6dee2fe334a6b56ef8d6b13876388cb5530366c7ffc7a46b3d9128f1cb7e6b57187f9cf698ace1
@@ -1,3 +1,12 @@
1
+ ## v0.2.0
2
+
3
+ ### Updates
4
+
5
+ - `provider` key now is mandatory;
6
+ - `provider` is only used on `production`;
7
+ - `provider` is auto setted by `redis` on `development` and `memory` on `test`;
8
+ - You can override auto set using env `SXS_PROVIDER` that overwrites `provider` on production too;
9
+
1
10
  ## v0.1.0
2
11
 
3
12
  ### News
data/README.md CHANGED
@@ -30,10 +30,11 @@ SXS::Publisher.new('some_key', provider: :redis).publish({ body: 'value' }.to_js
30
30
  SXS::Publisher.new('some_key', provider: :memory).publish({ body: 'value' }.to_json)
31
31
  ```
32
32
 
33
- If you do not specify the `provider` you will get:
33
+ On `development` and `test` environment `provider` be overwrited for the following:
34
34
 
35
35
  ```ruby
36
36
  development: :redis
37
- production: ArgumentError
38
37
  test: :memory
39
38
  ```
39
+
40
+ To avoid this ovewrite you can specify the provider via ENV `SXS_PROVIDER`. This will overwrites `production` too.
@@ -2,7 +2,7 @@
2
2
 
3
3
  module SXS
4
4
  class Publisher
5
- def initialize(queue_url, provider: nil)
5
+ def initialize(queue_url, provider:)
6
6
  @provider = provider
7
7
  @queue_url = queue_url
8
8
  end
@@ -21,18 +21,26 @@ module SXS
21
21
  SXS::Publishers::Memory
22
22
  end
23
23
 
24
- def publisher
25
- @publisher ||= provider.new(@queue_url)
24
+ def provider
25
+ return provider_select(ENV['SXS_PROVIDER']) unless ENV['SXS_PROVIDER'].nil?
26
+
27
+ return provider_select(@provider) if environment == 'production'
28
+
29
+ { 'development' => redis, 'test' => memory }[environment]
26
30
  end
27
31
 
28
- def provider
29
- return { memory: memory, redis: redis, sqs: sqs }[@provider.to_sym] if @provider
32
+ def provider_select(name)
33
+ value = { memory: memory, redis: redis, sqs: sqs }[name&.to_sym]
30
34
 
31
- if environment == 'production'
32
- raise ArgumentError, 'missing provider: redis, sqs, sns or memory'
35
+ if value.nil?
36
+ raise ArgumentError, 'Missing provider! Availables: :memory, :redis, :sns or :sqs'
33
37
  end
34
38
 
35
- { 'development' => redis, 'test' => memory }[environment]
39
+ value
40
+ end
41
+
42
+ def publisher
43
+ @publisher ||= provider.new(@queue_url)
36
44
  end
37
45
 
38
46
  def redis
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SXS
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -6,96 +6,344 @@ RSpec.describe SXS::Publisher, '#publish' do
6
6
  let!(:body) { { key: 'value' }.to_json }
7
7
  let!(:queue_url) { 'queue_url' }
8
8
 
9
- context 'when provider is given' do
10
- context 'when provider is sqs' do
11
- let(:provider) { :sqs }
9
+ after do
10
+ ENV['RAILS_ENV'] = 'test'
12
11
 
13
- let!(:sqs) { instance_spy 'SXS::Publishers::SQS' }
12
+ ENV.delete 'SXS_PROVIDER'
13
+ end
14
14
 
15
- before do
16
- allow(SXS::Publishers::SQS).to receive(:new).with(queue_url).and_return sqs
15
+ context 'when provider is sqs' do
16
+ let(:provider) { :sqs }
17
+
18
+ context 'when rails env is development' do
19
+ before { ENV['RAILS_ENV'] = 'development' }
20
+
21
+ context 'when sxs provider is not setted' do
22
+ let!(:redis) { instance_spy 'SXS::Publishers::Redis' }
23
+
24
+ before do
25
+ allow(SXS::Publishers::Redis).to receive(:new).with(queue_url).and_return redis
26
+ end
27
+
28
+ it 'overwrites with redis' do
29
+ publisher.publish body
30
+
31
+ expect(redis).to have_received(:publish).with(body)
32
+ end
17
33
  end
18
34
 
19
- it 'publishes the message' do
20
- publisher.publish body
35
+ context 'when sxs provider is setted' do
36
+ let!(:memory) { instance_spy 'SXS::Publishers::Memory' }
37
+
38
+ before do
39
+ allow(SXS::Publishers::Memory).to receive(:new).with(queue_url).and_return memory
40
+
41
+ ENV['SXS_PROVIDER'] = 'memory'
42
+ end
21
43
 
22
- expect(sqs).to have_received(:publish).with(body)
44
+ it 'is used' do
45
+ publisher.publish body
46
+
47
+ expect(memory).to have_received(:publish).with(body)
48
+ end
23
49
  end
24
50
  end
25
51
 
26
- context 'when provider is redis' do
27
- let(:provider) { :redis }
52
+ context 'when rails env is production' do
53
+ before { ENV['RAILS_ENV'] = 'production' }
28
54
 
29
- let!(:redis) { instance_spy 'SXS::Publishers::Redis' }
55
+ context 'when sxs provider is not setted' do
56
+ let!(:sqs) { instance_spy 'SXS::Publishers::SQS' }
30
57
 
31
- before do
32
- allow(SXS::Publishers::Redis).to receive(:new).with(queue_url).and_return redis
58
+ before do
59
+ allow(SXS::Publishers::SQS).to receive(:new).with(queue_url).and_return sqs
60
+ end
61
+
62
+ it 'uses the given provider' do
63
+ publisher.publish body
64
+
65
+ expect(sqs).to have_received(:publish).with(body)
66
+ end
33
67
  end
34
68
 
35
- it 'publishes the message' do
36
- publisher.publish body
69
+ context 'when sxs provider is setted' do
70
+ let!(:redis) { instance_spy 'SXS::Publishers::Redis' }
71
+
72
+ before do
73
+ allow(SXS::Publishers::Redis).to receive(:new).with(queue_url).and_return redis
37
74
 
38
- expect(redis).to have_received(:publish).with(body)
75
+ ENV['SXS_PROVIDER'] = 'redis'
76
+ end
77
+
78
+ it 'is used' do
79
+ publisher.publish body
80
+
81
+ expect(redis).to have_received(:publish).with(body)
82
+ end
39
83
  end
40
84
  end
41
85
 
42
- context 'when provider is memory' do
43
- let(:provider) { :memory }
86
+ context 'when rails env is test' do
87
+ before { ENV['RAILS_ENV'] = 'test' }
88
+
89
+ context 'when sxs provider is not setted' do
90
+ let!(:memory) { instance_spy 'SXS::Publishers::Memory' }
44
91
 
45
- let!(:memory) { instance_spy 'SXS::Publishers::Memory' }
92
+ before do
93
+ allow(SXS::Publishers::Memory).to receive(:new).with(queue_url).and_return memory
94
+ end
46
95
 
47
- before do
48
- allow(SXS::Publishers::Memory).to receive(:new).with(queue_url).and_return memory
96
+ it 'overwrites with memory' do
97
+ publisher.publish body
98
+
99
+ expect(memory).to have_received(:publish).with(body)
100
+ end
49
101
  end
50
102
 
51
- it 'publishes the message' do
52
- publisher.publish body
103
+ context 'when sxs provider is setted' do
104
+ let!(:redis) { instance_spy 'SXS::Publishers::Redis' }
105
+
106
+ before do
107
+ allow(SXS::Publishers::Redis).to receive(:new).with(queue_url).and_return redis
108
+
109
+ ENV['SXS_PROVIDER'] = 'redis'
110
+ end
111
+
112
+ it 'is used' do
113
+ publisher.publish body
53
114
 
54
- expect(memory).to have_received(:publish).with(body)
115
+ expect(redis).to have_received(:publish).with(body)
116
+ end
55
117
  end
56
118
  end
57
119
  end
58
120
 
59
- context 'when provider is not given' do
60
- let(:provider) { nil }
121
+ context 'when provider is redis' do
122
+ let(:provider) { :redis }
61
123
 
62
124
  context 'when rails env is development' do
63
- let!(:redis) { instance_spy 'SXS::Publishers::Redis' }
125
+ before { ENV['RAILS_ENV'] = 'development' }
64
126
 
65
- before do
66
- allow(ENV).to receive(:[]).with('RAILS_ENV').and_return 'development'
67
- allow(SXS::Publishers::Redis).to receive(:new).with(queue_url).and_return redis
127
+ context 'when sxs provider is not setted' do
128
+ let!(:redis) { instance_spy 'SXS::Publishers::Redis' }
129
+
130
+ before do
131
+ allow(SXS::Publishers::Redis).to receive(:new).with(queue_url).and_return redis
132
+ end
133
+
134
+ it 'overwrites with redis' do
135
+ publisher.publish body
136
+
137
+ expect(redis).to have_received(:publish).with(body)
138
+ end
68
139
  end
69
140
 
70
- it 'publishes the message on redis' do
71
- publisher.publish body
141
+ context 'when sxs provider is setted' do
142
+ let!(:memory) { instance_spy 'SXS::Publishers::Memory' }
143
+
144
+ before do
145
+ allow(SXS::Publishers::Memory).to receive(:new).with(queue_url).and_return memory
146
+
147
+ ENV['SXS_PROVIDER'] = 'memory'
148
+ end
72
149
 
73
- expect(redis).to have_received(:publish).with(body)
150
+ it 'is used' do
151
+ publisher.publish body
152
+
153
+ expect(memory).to have_received(:publish).with(body)
154
+ end
74
155
  end
75
156
  end
76
157
 
77
158
  context 'when rails env is production' do
78
- let!(:error) { 'missing provider: redis, sqs, sns or memory' }
159
+ before { ENV['RAILS_ENV'] = 'production' }
160
+
161
+ context 'when sxs provider is not setted' do
162
+ let!(:redis) { instance_spy 'SXS::Publishers::Redis' }
163
+
164
+ before do
165
+ allow(SXS::Publishers::Redis).to receive(:new).with(queue_url).and_return redis
166
+ end
167
+
168
+ it 'uses the given provider' do
169
+ publisher.publish body
170
+
171
+ expect(redis).to have_received(:publish).with(body)
172
+ end
173
+ end
79
174
 
80
- before { allow(ENV).to receive(:[]).with('RAILS_ENV').and_return 'production' }
175
+ context 'when sxs provider is setted' do
176
+ let!(:memory) { instance_spy 'SXS::Publishers::Memory' }
81
177
 
82
- it 'raises' do
83
- expect { publisher.publish body }.to raise_error ArgumentError, error
178
+ before do
179
+ allow(SXS::Publishers::Memory).to receive(:new).with(queue_url).and_return memory
180
+
181
+ ENV['SXS_PROVIDER'] = 'memory'
182
+ end
183
+
184
+ it 'is used' do
185
+ publisher.publish body
186
+
187
+ expect(memory).to have_received(:publish).with(body)
188
+ end
84
189
  end
85
190
  end
86
191
 
87
192
  context 'when rails env is test' do
88
- let!(:memory) { instance_spy 'SXS::Publishers::Memory' }
193
+ before do
194
+ ENV['RAILS_ENV'] = 'test'
195
+ end
196
+
197
+ after do
198
+ ENV['RAILS_ENV'] = 'test'
199
+ end
200
+
201
+ context 'when sxs provider is not setted' do
202
+ let!(:memory) { instance_spy 'SXS::Publishers::Memory' }
203
+
204
+ before do
205
+ allow(SXS::Publishers::Memory).to receive(:new).with(queue_url).and_return memory
206
+ end
207
+
208
+ it 'overwrites with memory' do
209
+ publisher.publish body
210
+
211
+ expect(memory).to have_received(:publish).with(body)
212
+ end
213
+ end
89
214
 
215
+ context 'when sxs provider is setted' do
216
+ let!(:memory) { instance_spy 'SXS::Publishers::Memory' }
217
+
218
+ before do
219
+ allow(SXS::Publishers::Memory).to receive(:new).with(queue_url).and_return memory
220
+ end
221
+
222
+ before do
223
+ ENV['SXS_PROVIDER'] = 'memory'
224
+ end
225
+
226
+ after do
227
+ ENV.delete 'SXS_PROVIDER'
228
+ end
229
+
230
+ it 'is used' do
231
+ publisher.publish body
232
+
233
+ expect(memory).to have_received(:publish).with(body)
234
+ end
235
+ end
236
+ end
237
+ end
238
+
239
+ context 'when provider is memory' do
240
+ let(:provider) { :memory }
241
+
242
+ context 'when rails env is development' do
90
243
  before do
91
- allow(ENV).to receive(:[]).with('RAILS_ENV').and_return 'test'
92
- allow(SXS::Publishers::Memory).to receive(:new).with(queue_url).and_return memory
244
+ ENV['RAILS_ENV'] = 'development'
245
+ end
246
+
247
+ after do
248
+ ENV['RAILS_ENV'] = 'test'
93
249
  end
94
250
 
95
- it 'publishes the message on memory' do
96
- publisher.publish body
251
+ context 'when sxs provider is not setted' do
252
+ let!(:redis) { instance_spy 'SXS::Publishers::Redis' }
253
+
254
+ before do
255
+ allow(SXS::Publishers::Redis).to receive(:new).with(queue_url).and_return redis
256
+ end
257
+
258
+ it 'overwrites with redis' do
259
+ publisher.publish body
260
+
261
+ expect(redis).to have_received(:publish).with(body)
262
+ end
263
+ end
264
+
265
+ context 'when sxs provider is setted' do
266
+ let!(:redis) { instance_spy 'SXS::Publishers::Redis' }
267
+
268
+ before do
269
+ allow(SXS::Publishers::Redis).to receive(:new).with(queue_url).and_return redis
270
+
271
+ ENV['SXS_PROVIDER'] = 'redis'
272
+ end
273
+
274
+ it 'is used' do
275
+ publisher.publish body
276
+
277
+ expect(redis).to have_received(:publish).with(body)
278
+ end
279
+ end
280
+ end
281
+
282
+ context 'when rails env is production' do
283
+ before { ENV['RAILS_ENV'] = 'production' }
284
+
285
+ context 'when sxs provider is not setted' do
286
+ let!(:memory) { instance_spy 'SXS::Publishers::Memory' }
287
+
288
+ before do
289
+ allow(SXS::Publishers::Memory).to receive(:new).with(queue_url).and_return memory
290
+ end
291
+
292
+ it 'uses the given provider' do
293
+ publisher.publish body
294
+
295
+ expect(memory).to have_received(:publish).with(body)
296
+ end
297
+ end
298
+
299
+ context 'when sxs provider is setted' do
300
+ let!(:redis) { instance_spy 'SXS::Publishers::Redis' }
301
+
302
+ before do
303
+ allow(SXS::Publishers::Redis).to receive(:new).with(queue_url).and_return redis
304
+
305
+ ENV['SXS_PROVIDER'] = 'redis'
306
+ end
307
+
308
+ it 'is used' do
309
+ publisher.publish body
310
+
311
+ expect(redis).to have_received(:publish).with(body)
312
+ end
313
+ end
314
+ end
315
+
316
+ context 'when rails env is test' do
317
+ before { ENV['RAILS_ENV'] = 'test' }
318
+
319
+ context 'when sxs provider is not setted' do
320
+ let!(:memory) { instance_spy 'SXS::Publishers::Memory' }
321
+
322
+ before do
323
+ allow(SXS::Publishers::Memory).to receive(:new).with(queue_url).and_return memory
324
+ end
325
+
326
+ it 'overwrites with memory' do
327
+ publisher.publish body
328
+
329
+ expect(memory).to have_received(:publish).with(body)
330
+ end
331
+ end
332
+
333
+ context 'when sxs provider is setted' do
334
+ let!(:redis) { instance_spy 'SXS::Publishers::Redis' }
335
+
336
+ before do
337
+ allow(SXS::Publishers::Redis).to receive(:new).with(queue_url).and_return redis
338
+
339
+ ENV['SXS_PROVIDER'] = 'redis'
340
+ end
341
+
342
+ it 'is used' do
343
+ publisher.publish body
97
344
 
98
- expect(memory).to have_received(:publish).with(body)
345
+ expect(redis).to have_received(:publish).with(body)
346
+ end
99
347
  end
100
348
  end
101
349
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sxs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Botelho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-26 00:00:00.000000000 Z
11
+ date: 2019-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-sns
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description: SNS/SQS wrapper to make `development` (Redis) and `test` (Memory) environment
125
+ description: SNS/SQS wrapper to make development (Redis) and test (Memory) environment
126
126
  transparent.
127
127
  email: wbotelhos@gmail.com
128
128
  executables: []