sxs 0.1.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +39 -0
- data/lib/generators/sxs/install_generator.rb +13 -0
- data/lib/generators/sxs/templates/config/initializers/sxs.rb +5 -0
- data/lib/sxs.rb +17 -0
- data/lib/sxs/config.rb +15 -0
- data/lib/sxs/publisher.rb +46 -0
- data/lib/sxs/publishers.rb +9 -0
- data/lib/sxs/publishers/memory.rb +34 -0
- data/lib/sxs/publishers/redis.rb +21 -0
- data/lib/sxs/publishers/sqs.rb +24 -0
- data/lib/sxs/version.rb +5 -0
- data/spec/rails_helper.rb +23 -0
- data/spec/sxs/config/redis_config_spec.rb +7 -0
- data/spec/sxs/config/redis_spec.rb +11 -0
- data/spec/sxs/configure_spec.rb +9 -0
- data/spec/sxs/publisher/publish_spec.rb +102 -0
- data/spec/sxs/publishers/memory/clear_spec.rb +17 -0
- data/spec/sxs/publishers/memory/include_spec.rb +18 -0
- data/spec/sxs/publishers/memory/messages_spec.rb +13 -0
- data/spec/sxs/publishers/memory/publish_spec.rb +13 -0
- data/spec/sxs/publishers/memory/queues_spec.rb +19 -0
- data/spec/sxs/publishers/memory/size_spec.rb +14 -0
- data/spec/sxs/publishers/redis/publish_spec.rb +14 -0
- data/spec/sxs/publishers/sqs/publish_spec.rb +38 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 93243c7fda169668829a419181bbe7136e24ebbc9eb245108182995899abde7b
|
4
|
+
data.tar.gz: f4e9b2f8eeb6c5f397405ad8badd7cd61a04e32f44ac9cc7625799c2bcf14f66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 45059b39c7cf5f1ff0ccfd7e8526544c38934dd14cf5a6d20172e232d18a217691a4b4f6c764ff5165a5083999977d8139bca0bfafa5ec979c265ac77c1b8c7d
|
7
|
+
data.tar.gz: d28d6de75c87dd17f251a8bf2a92da6f0f41acac2a65a2eaa4c5b58e7a8a127ad209e03c47378c8e2cc4bf737f03f3a1a325c4323f11acc03765886f32f1b81a
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Washington Botelho
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# SXS
|
2
|
+
|
3
|
+
[](https://travis-ci.org/wbotelhos/sxs)
|
4
|
+
[](https://badge.fury.io/rb/sxs)
|
5
|
+
[](https://codeclimate.com/github/wbotelhos/sxs/maintainability)
|
6
|
+
[](https://www.patreon.com/wbotelhos)
|
7
|
+
|
8
|
+
SNS/SQS wrapper to make `development` (Redis) and `test` (Memory) environment transparent.
|
9
|
+
|
10
|
+
## Install
|
11
|
+
|
12
|
+
Add the following code on your `Gemfile` and run `bundle install`:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'sxs'
|
16
|
+
```
|
17
|
+
|
18
|
+
Run the following task to create a SXS migration:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
rails g sxs:install
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
SXS::Publisher.new('sqs_url', provider: :sqs).publish({ body: 'value' }.to_json)
|
28
|
+
SXS::Publisher.new('sns_url', provider: :sns).publish({ body: 'value' }.to_json)
|
29
|
+
SXS::Publisher.new('some_key', provider: :redis).publish({ body: 'value' }.to_json)
|
30
|
+
SXS::Publisher.new('some_key', provider: :memory).publish({ body: 'value' }.to_json)
|
31
|
+
```
|
32
|
+
|
33
|
+
If you do not specify the `provider` you will get:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
development: :redis
|
37
|
+
production: ArgumentError
|
38
|
+
test: :memory
|
39
|
+
```
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SXS
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('templates', __dir__)
|
6
|
+
|
7
|
+
desc 'creates an initializer'
|
8
|
+
|
9
|
+
def copy_initializer
|
10
|
+
copy_file 'config/initializers/sxs.rb', 'config/initializers/sxs.rb'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/sxs.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SXS
|
4
|
+
require 'sxs/config'
|
5
|
+
require 'sxs/publisher'
|
6
|
+
require 'sxs/publishers'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def config
|
10
|
+
@config ||= ::SXS::Config.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure
|
14
|
+
yield config
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/sxs/config.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SXS
|
4
|
+
class Publisher
|
5
|
+
def initialize(queue_url, provider: nil)
|
6
|
+
@provider = provider
|
7
|
+
@queue_url = queue_url
|
8
|
+
end
|
9
|
+
|
10
|
+
def publish(body)
|
11
|
+
publisher.publish(body)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def environment
|
17
|
+
ENV['RAILS_ENV']
|
18
|
+
end
|
19
|
+
|
20
|
+
def memory
|
21
|
+
SXS::Publishers::Memory
|
22
|
+
end
|
23
|
+
|
24
|
+
def publisher
|
25
|
+
@publisher ||= provider.new(@queue_url)
|
26
|
+
end
|
27
|
+
|
28
|
+
def provider
|
29
|
+
return { memory: memory, redis: redis, sqs: sqs }[@provider.to_sym] if @provider
|
30
|
+
|
31
|
+
if environment == 'production'
|
32
|
+
raise ArgumentError, 'missing provider: redis, sqs, sns or memory'
|
33
|
+
end
|
34
|
+
|
35
|
+
{ 'development' => redis, 'test' => memory }[environment]
|
36
|
+
end
|
37
|
+
|
38
|
+
def redis
|
39
|
+
SXS::Publishers::Redis
|
40
|
+
end
|
41
|
+
|
42
|
+
def sqs
|
43
|
+
SXS::Publishers::SQS
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SXS
|
4
|
+
module Publishers
|
5
|
+
class Memory
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
attr_reader :queue_url
|
9
|
+
|
10
|
+
def_delegators :messages, :include?, :size
|
11
|
+
|
12
|
+
def initialize(queue_url)
|
13
|
+
@queue_url = queue_url
|
14
|
+
end
|
15
|
+
|
16
|
+
def messages
|
17
|
+
self.class.queues[@queue_url]
|
18
|
+
end
|
19
|
+
|
20
|
+
def publish(body)
|
21
|
+
self.class.queues[@queue_url] ||= []
|
22
|
+
self.class.queues[@queue_url] << body
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.clear
|
26
|
+
@queues = {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.queues
|
30
|
+
@queues ||= {}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SXS
|
4
|
+
module Publishers
|
5
|
+
class Redis
|
6
|
+
def initialize(queue_url)
|
7
|
+
@queue_url = queue_url
|
8
|
+
end
|
9
|
+
|
10
|
+
def publish(body)
|
11
|
+
redis.rpush @queue_url, body
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def redis
|
17
|
+
@redis ||= ::Redis.new(::SXS.config.redis_config)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SXS
|
4
|
+
module Publishers
|
5
|
+
require 'aws-sdk-sqs'
|
6
|
+
|
7
|
+
class SQS
|
8
|
+
def initialize(queue_url, resource: ::Aws::SQS::Resource)
|
9
|
+
@queue_url = queue_url
|
10
|
+
@resource = resource
|
11
|
+
end
|
12
|
+
|
13
|
+
def publish(body)
|
14
|
+
queue.send_message message_body: body
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def queue
|
20
|
+
@queue ||= @resource.new.queue(@queue_url)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/sxs/version.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
ENV['RAILS_ENV'] ||= 'test'
|
4
|
+
|
5
|
+
require 'fakeredis/rspec'
|
6
|
+
require 'pry-byebug'
|
7
|
+
require 'rspec'
|
8
|
+
require 'sxs'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.disable_monkey_patching!
|
12
|
+
|
13
|
+
config.after(:each, :sxs) do
|
14
|
+
SXS::Publishers::Memory.clear
|
15
|
+
end
|
16
|
+
|
17
|
+
config.mock_with :rspec do |mocks|
|
18
|
+
mocks.verify_partial_doubles = true
|
19
|
+
end
|
20
|
+
|
21
|
+
config.order = :random
|
22
|
+
config.profile_examples = true
|
23
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe SXS::Config, 'redis' do
|
4
|
+
subject(:config) { described_class.new }
|
5
|
+
|
6
|
+
before { config.redis db: 0, host: :localhost, port: 6379 }
|
7
|
+
|
8
|
+
it 'overwrite the config' do
|
9
|
+
expect(config.redis_config).to eq(db: 0, host: :localhost, port: 6379)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe SXS::Publisher, '#publish' do
|
4
|
+
subject(:publisher) { described_class.new queue_url, provider: provider }
|
5
|
+
|
6
|
+
let!(:body) { { key: 'value' }.to_json }
|
7
|
+
let!(:queue_url) { 'queue_url' }
|
8
|
+
|
9
|
+
context 'when provider is given' do
|
10
|
+
context 'when provider is sqs' do
|
11
|
+
let(:provider) { :sqs }
|
12
|
+
|
13
|
+
let!(:sqs) { instance_spy 'SXS::Publishers::SQS' }
|
14
|
+
|
15
|
+
before do
|
16
|
+
allow(SXS::Publishers::SQS).to receive(:new).with(queue_url).and_return sqs
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'publishes the message' do
|
20
|
+
publisher.publish body
|
21
|
+
|
22
|
+
expect(sqs).to have_received(:publish).with(body)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when provider is redis' do
|
27
|
+
let(:provider) { :redis }
|
28
|
+
|
29
|
+
let!(:redis) { instance_spy 'SXS::Publishers::Redis' }
|
30
|
+
|
31
|
+
before do
|
32
|
+
allow(SXS::Publishers::Redis).to receive(:new).with(queue_url).and_return redis
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'publishes the message' do
|
36
|
+
publisher.publish body
|
37
|
+
|
38
|
+
expect(redis).to have_received(:publish).with(body)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when provider is memory' do
|
43
|
+
let(:provider) { :memory }
|
44
|
+
|
45
|
+
let!(:memory) { instance_spy 'SXS::Publishers::Memory' }
|
46
|
+
|
47
|
+
before do
|
48
|
+
allow(SXS::Publishers::Memory).to receive(:new).with(queue_url).and_return memory
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'publishes the message' do
|
52
|
+
publisher.publish body
|
53
|
+
|
54
|
+
expect(memory).to have_received(:publish).with(body)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when provider is not given' do
|
60
|
+
let(:provider) { nil }
|
61
|
+
|
62
|
+
context 'when rails env is development' do
|
63
|
+
let!(:redis) { instance_spy 'SXS::Publishers::Redis' }
|
64
|
+
|
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
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'publishes the message on redis' do
|
71
|
+
publisher.publish body
|
72
|
+
|
73
|
+
expect(redis).to have_received(:publish).with(body)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when rails env is production' do
|
78
|
+
let!(:error) { 'missing provider: redis, sqs, sns or memory' }
|
79
|
+
|
80
|
+
before { allow(ENV).to receive(:[]).with('RAILS_ENV').and_return 'production' }
|
81
|
+
|
82
|
+
it 'raises' do
|
83
|
+
expect { publisher.publish body }.to raise_error ArgumentError, error
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when rails env is test' do
|
88
|
+
let!(:memory) { instance_spy 'SXS::Publishers::Memory' }
|
89
|
+
|
90
|
+
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
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'publishes the message on memory' do
|
96
|
+
publisher.publish body
|
97
|
+
|
98
|
+
expect(memory).to have_received(:publish).with(body)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe SXS::Publishers::Memory, '.clear' do
|
4
|
+
let!(:publisher_1) { described_class.new 'queue_url_1' }
|
5
|
+
let!(:publisher_2) { described_class.new 'queue_url_2' }
|
6
|
+
|
7
|
+
before do
|
8
|
+
publisher_1.publish({ key: 'value.1' }.to_json)
|
9
|
+
publisher_2.publish({ key: 'value.2' }.to_json)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'clears the queues', :sxs do
|
13
|
+
described_class.clear
|
14
|
+
|
15
|
+
expect(described_class.queues).to eq({})
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe SXS::Publishers::Memory, '#include?' do
|
4
|
+
let!(:publisher_1) { described_class.new 'queue_url_1' }
|
5
|
+
let!(:publisher_2) { described_class.new 'queue_url_2' }
|
6
|
+
|
7
|
+
before do
|
8
|
+
publisher_1.publish({ key: 'value.1' }.to_json)
|
9
|
+
publisher_1.publish({ key: 'value.2' }.to_json)
|
10
|
+
publisher_2.publish({ key: 'value.3' }.to_json)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'checks if given message is included on queue', :sxs do
|
14
|
+
expect(publisher_1.include?('{"key":"value.1"}')).to eq true
|
15
|
+
expect(publisher_1.include?('{"key":"missing"}')).to eq false
|
16
|
+
expect(publisher_2.include?('{"key":"value.3"}')).to eq true
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe SXS::Publishers::Memory, '#messages' do
|
4
|
+
let!(:body) { { key: 'value' }.to_json }
|
5
|
+
let!(:queue_url) { 'queue_url' }
|
6
|
+
let!(:publisher) { described_class.new queue_url }
|
7
|
+
|
8
|
+
it 'returns the messages', :sxs do
|
9
|
+
publisher.publish body
|
10
|
+
|
11
|
+
expect(publisher.messages).to eq ['{"key":"value"}']
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe SXS::Publishers::Memory, '#publish' do
|
4
|
+
let!(:body) { { key: 'value' }.to_json }
|
5
|
+
let!(:queue_url) { 'queue_url' }
|
6
|
+
let!(:publisher) { described_class.new queue_url }
|
7
|
+
|
8
|
+
it 'publishes the message', :sxs do
|
9
|
+
publisher.publish body
|
10
|
+
|
11
|
+
expect(publisher.messages).to eq ['{"key":"value"}']
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe SXS::Publishers::Memory, '.queues' do
|
4
|
+
let!(:publisher_1) { described_class.new 'queue_url_1' }
|
5
|
+
let!(:publisher_2) { described_class.new 'queue_url_2' }
|
6
|
+
|
7
|
+
before do
|
8
|
+
publisher_1.publish({ key: 'value.1' }.to_json)
|
9
|
+
publisher_1.publish({ key: 'value.2' }.to_json)
|
10
|
+
publisher_2.publish({ key: 'value.3' }.to_json)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns the queues with its messages', :sxs do
|
14
|
+
expect(described_class.queues).to eq(
|
15
|
+
'queue_url_1' => ['{"key":"value.1"}', '{"key":"value.2"}'],
|
16
|
+
'queue_url_2' => ['{"key":"value.3"}']
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe SXS::Publishers::Memory, '#size' do
|
4
|
+
let!(:publisher) { described_class.new 'queue_url' }
|
5
|
+
|
6
|
+
before do
|
7
|
+
publisher.publish({ key: 'value.1' }.to_json)
|
8
|
+
publisher.publish({ key: 'value.2' }.to_json)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns the size of items on queues', :sxs do
|
12
|
+
expect(publisher.size).to eq 2
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe SXS::Publishers::Redis, '#publish' do
|
4
|
+
let!(:body) { { key: 'value' }.to_json }
|
5
|
+
let!(:queue_url) { 'queue_url' }
|
6
|
+
let!(:publisher) { described_class.new queue_url }
|
7
|
+
let!(:redis) { ::Redis.new }
|
8
|
+
|
9
|
+
it 'publishes the message' do
|
10
|
+
publisher.publish body
|
11
|
+
|
12
|
+
expect(redis.rpop(queue_url)).to eq '{"key":"value"}'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe SXS::Publishers::SQS, '#publish' do
|
4
|
+
let!(:body) { { key: 'value' }.to_json }
|
5
|
+
let!(:queue) { instance_spy 'Aws::SQS::Queue' }
|
6
|
+
let!(:queue_url) { 'queue_url' }
|
7
|
+
let!(:resource_client) { instance_double 'Aws::SQS::Resource' }
|
8
|
+
|
9
|
+
context 'when resource is not injected' do
|
10
|
+
let!(:publisher) { described_class.new queue_url }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(::Aws::SQS::Resource).to receive(:new).and_return resource_client
|
14
|
+
allow(resource_client).to receive(:queue).with(queue_url).and_return queue
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'publishes the message' do
|
18
|
+
publisher.publish body
|
19
|
+
|
20
|
+
expect(queue).to have_received(:send_message).with(message_body: body)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when resource is injected' do
|
25
|
+
let!(:resource) { class_double 'Aws::SQS::Resource', new: resource_client }
|
26
|
+
let!(:publisher) { described_class.new queue_url, resource: resource }
|
27
|
+
|
28
|
+
before do
|
29
|
+
allow(resource_client).to receive(:queue).with(queue_url).and_return queue
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'publishes the message' do
|
33
|
+
publisher.publish body
|
34
|
+
|
35
|
+
expect(queue).to have_received(:send_message).with(message_body: body)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sxs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Washington Botelho
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk-sns
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk-sqs
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: redis
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fakeredis
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: SNS/SQS wrapper to make `development` (Redis) and `test` (Memory) environment
|
126
|
+
transparent.
|
127
|
+
email: wbotelhos@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- CHANGELOG.md
|
133
|
+
- LICENSE
|
134
|
+
- README.md
|
135
|
+
- lib/generators/sxs/install_generator.rb
|
136
|
+
- lib/generators/sxs/templates/config/initializers/sxs.rb
|
137
|
+
- lib/sxs.rb
|
138
|
+
- lib/sxs/config.rb
|
139
|
+
- lib/sxs/publisher.rb
|
140
|
+
- lib/sxs/publishers.rb
|
141
|
+
- lib/sxs/publishers/memory.rb
|
142
|
+
- lib/sxs/publishers/redis.rb
|
143
|
+
- lib/sxs/publishers/sqs.rb
|
144
|
+
- lib/sxs/version.rb
|
145
|
+
- spec/rails_helper.rb
|
146
|
+
- spec/sxs/config/redis_config_spec.rb
|
147
|
+
- spec/sxs/config/redis_spec.rb
|
148
|
+
- spec/sxs/configure_spec.rb
|
149
|
+
- spec/sxs/publisher/publish_spec.rb
|
150
|
+
- spec/sxs/publishers/memory/clear_spec.rb
|
151
|
+
- spec/sxs/publishers/memory/include_spec.rb
|
152
|
+
- spec/sxs/publishers/memory/messages_spec.rb
|
153
|
+
- spec/sxs/publishers/memory/publish_spec.rb
|
154
|
+
- spec/sxs/publishers/memory/queues_spec.rb
|
155
|
+
- spec/sxs/publishers/memory/size_spec.rb
|
156
|
+
- spec/sxs/publishers/redis/publish_spec.rb
|
157
|
+
- spec/sxs/publishers/sqs/publish_spec.rb
|
158
|
+
homepage: https://github.com/wbotelhos/sxs
|
159
|
+
licenses:
|
160
|
+
- MIT
|
161
|
+
metadata: {}
|
162
|
+
post_install_message:
|
163
|
+
rdoc_options: []
|
164
|
+
require_paths:
|
165
|
+
- lib
|
166
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
requirements: []
|
177
|
+
rubygems_version: 3.0.3
|
178
|
+
signing_key:
|
179
|
+
specification_version: 4
|
180
|
+
summary: SNS and SQS Wrapper.
|
181
|
+
test_files:
|
182
|
+
- spec/sxs/config/redis_config_spec.rb
|
183
|
+
- spec/sxs/config/redis_spec.rb
|
184
|
+
- spec/sxs/publisher/publish_spec.rb
|
185
|
+
- spec/sxs/publishers/memory/clear_spec.rb
|
186
|
+
- spec/sxs/publishers/memory/publish_spec.rb
|
187
|
+
- spec/sxs/publishers/memory/messages_spec.rb
|
188
|
+
- spec/sxs/publishers/memory/queues_spec.rb
|
189
|
+
- spec/sxs/publishers/memory/size_spec.rb
|
190
|
+
- spec/sxs/publishers/memory/include_spec.rb
|
191
|
+
- spec/sxs/publishers/redis/publish_spec.rb
|
192
|
+
- spec/sxs/publishers/sqs/publish_spec.rb
|
193
|
+
- spec/sxs/configure_spec.rb
|
194
|
+
- spec/rails_helper.rb
|