bunny-publisher 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +26 -0
- data/lib/bunny_publisher.rb +18 -2
- data/lib/bunny_publisher/test.rb +33 -0
- data/lib/bunny_publisher/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81976f1ec6350ac4bd2ec4182f0b0c42dcb99705b014228f896f5183bf3e02af
|
4
|
+
data.tar.gz: 15cc8eef3348d2eff8367aa3f8167a1762e9a94fa56506168f47618ee857e7ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d67b3c8e5a609b61450452a8f87aaa281ee458d10f3c5d551e45b8ab5bdf9fb07e75df06525f7df803b88129a5412229a26f485f4f602d71cf309cc737619806
|
7
|
+
data.tar.gz: 4cdf52e2d3f6a8f99156b0e7359b6a3bf54841ae80ea3cf461c3ab8f1e105a0cc66d0d7e6cc3a0d25812b607dfddb8222b330508c49821866528cc5f589948e3
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -111,6 +111,32 @@ end
|
|
111
111
|
|
112
112
|
Not implemented yet
|
113
113
|
|
114
|
+
## Test mode
|
115
|
+
|
116
|
+
BunnyPublisher also has a test mode which replaces exchange and prevents real connection to RabbitMQ
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
BunnyPublisher.configure do |c|
|
120
|
+
c.test = true # or Rails.env.test?
|
121
|
+
|
122
|
+
# ...
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
Now publisher has `#messages`, `#flush!` methods:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
describe SomeServiceThatPublishesToRabbitMQ, '#call' do
|
130
|
+
subject { described_class.new(some: 'attributes').call }
|
131
|
+
|
132
|
+
before { BunnyPublisher.flush! }
|
133
|
+
|
134
|
+
it 'publishes a message' do
|
135
|
+
expect { subject }.to change(BunnyPublisher.messages).by(1)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
```
|
139
|
+
|
114
140
|
## Contributing
|
115
141
|
|
116
142
|
Bug reports and pull requests are welcome on GitHub at https://github.com/veeqo/bunny-publisher.
|
data/lib/bunny_publisher.rb
CHANGED
@@ -6,6 +6,7 @@ require 'bunny_publisher/callbacks'
|
|
6
6
|
require 'bunny_publisher/errors'
|
7
7
|
require 'bunny_publisher/base'
|
8
8
|
require 'bunny_publisher/mandatory'
|
9
|
+
require 'bunny_publisher/test'
|
9
10
|
|
10
11
|
module BunnyPublisher
|
11
12
|
class << self
|
@@ -20,13 +21,28 @@ module BunnyPublisher
|
|
20
21
|
def configure
|
21
22
|
require 'ostruct'
|
22
23
|
|
23
|
-
config = OpenStruct.new(
|
24
|
+
config = OpenStruct.new(mandatory: false, test: false)
|
24
25
|
|
25
26
|
yield(config)
|
26
27
|
|
27
|
-
klass = Class.new(Base)
|
28
|
+
klass = Class.new(Base) do
|
29
|
+
include ::BunnyPublisher::Mandatory if config.delete_field(:mandatory)
|
30
|
+
include ::BunnyPublisher::Test if config.delete_field(:test)
|
31
|
+
end
|
28
32
|
|
29
33
|
@publisher = klass.new(config.to_h)
|
30
34
|
end
|
35
|
+
|
36
|
+
def method_missing(method_name, *args)
|
37
|
+
if publisher.respond_to?(method_name)
|
38
|
+
publisher.send(method_name, *args)
|
39
|
+
else
|
40
|
+
super
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def respond_to_missing?(method_name, include_private = false)
|
45
|
+
publisher.respond_to?(method_name) || super
|
46
|
+
end
|
31
47
|
end
|
32
48
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BunnyPublisher
|
4
|
+
# Test module prevents real connections to be made and replaces exchange with array-based TestExchange
|
5
|
+
module Test
|
6
|
+
class TestExchange < Array
|
7
|
+
def publish(message, options = {})
|
8
|
+
self << [message, options]
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
# in case if used with Mandatory module included
|
13
|
+
def on_return(&block); end
|
14
|
+
end
|
15
|
+
|
16
|
+
def exchange
|
17
|
+
@exchange ||= TestExchange.new
|
18
|
+
end
|
19
|
+
|
20
|
+
alias messages exchange
|
21
|
+
|
22
|
+
def flush!
|
23
|
+
exchange.clear
|
24
|
+
end
|
25
|
+
|
26
|
+
alias close flush!
|
27
|
+
alias stop flush!
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def ensure_connection!; end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunny-publisher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Sharshenov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/bunny_publisher/callbacks.rb
|
118
118
|
- lib/bunny_publisher/errors.rb
|
119
119
|
- lib/bunny_publisher/mandatory.rb
|
120
|
+
- lib/bunny_publisher/test.rb
|
120
121
|
- lib/bunny_publisher/version.rb
|
121
122
|
homepage: https://github.com/veeqo/bunny-publisher
|
122
123
|
licenses:
|