announce 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -4
- data/lib/announce/testing.rb +47 -0
- data/lib/announce/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 657b17523c88c350d69e1b1de4393ff2b3d0c803
|
4
|
+
data.tar.gz: 9a2bb7fc21061b94e0af76a82129faba9e28e0a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 513d312adeeb87a82e89edff4f8ad19849a5303a451655f040aca03e06e2631c2210f3992ef05c94b5b206d28d0803037bd09ed82e025b3435d936fa7283a3f4
|
7
|
+
data.tar.gz: 037d43cabac0a80227d75289dfc3d80886d6ded53c45ab7255f4476a67ef707d98db4a0694eaa6a7cb3e3f5ec4dc4ec54499ef8a5695353e1ed712d80e840da8
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ end
|
|
32
32
|
```
|
33
33
|
|
34
34
|
When building a Ruby app or service to receive messages, subscribe a job class to announcements like this:
|
35
|
-
```
|
35
|
+
```ruby
|
36
36
|
require 'announce'
|
37
37
|
|
38
38
|
class SomeCreateJob < ActiveJob::Base
|
@@ -223,7 +223,7 @@ Announce.announce(:story, :publish, id: story.id, {})
|
|
223
223
|
```
|
224
224
|
|
225
225
|
There is also a module you can include to get `publish` and `announce` methods:
|
226
|
-
```
|
226
|
+
```ruby
|
227
227
|
class SomeController
|
228
228
|
include Announce::Publisher
|
229
229
|
|
@@ -247,7 +247,7 @@ Unlike other job libraries which specify the Ruby `Class` for processing as part
|
|
247
247
|
|
248
248
|
To designate that a Ruby class will process a message, you must include the `Announce:Subscriber` module and call `subscribe_to` class method.
|
249
249
|
|
250
|
-
```
|
250
|
+
```ruby
|
251
251
|
require 'announce'
|
252
252
|
|
253
253
|
class SomeCreateJob < ActiveJob::Base
|
@@ -264,7 +264,7 @@ end
|
|
264
264
|
This works because the `Announce::Subscriber` adds the `subscribe_to` class method, but also a default `perform(*args)` instance method that delegates message handling to a job instance method named `"receive_#{subject}_#{action}"`.
|
265
265
|
|
266
266
|
This default `perform` method only passes the message `body` to `receive_subject_action` methods. The `subject`, but `action` and full `message` object are made available as instance properties of the subscriber.
|
267
|
-
```
|
267
|
+
```ruby
|
268
268
|
require 'announce'
|
269
269
|
|
270
270
|
class SomeCreateJob < ActiveJob::Base
|
@@ -302,6 +302,42 @@ For `shoryuken`, `subscribe_to` registers the worker for the appropriate queue,
|
|
302
302
|
|
303
303
|
## Development
|
304
304
|
|
305
|
+
### Testing with Announce
|
306
|
+
|
307
|
+
There is an Announce::Testing module which provides helper methods useful in your tests.
|
308
|
+
To use them add the following lines into your test/spec helper:
|
309
|
+
```ruby
|
310
|
+
# use the testing helper
|
311
|
+
require 'announce/testing'
|
312
|
+
|
313
|
+
# include the methods - could also include in your base test class
|
314
|
+
include Announce::Testing
|
315
|
+
|
316
|
+
# this resets announce to use test settings, and clears messages
|
317
|
+
reset_announce
|
318
|
+
|
319
|
+
```
|
320
|
+
|
321
|
+
Then you can use the following methods in your test class:
|
322
|
+
|
323
|
+
`published_messages` - returns the array of published messages
|
324
|
+
|
325
|
+
`last_message` - returns the last message published to announce
|
326
|
+
|
327
|
+
`clear_messages` - clears all published messages
|
328
|
+
|
329
|
+
`subscriptions` - returns the array of all subscriptions
|
330
|
+
|
331
|
+
`last_subscription` - returns most recently added subscription
|
332
|
+
|
333
|
+
`clear_subscriptions` - clears all subscriptions
|
334
|
+
|
335
|
+
`broker_configured?` - returns whether or not the broker has been configured
|
336
|
+
|
337
|
+
`reset_broker_config` - resets broker
|
338
|
+
|
339
|
+
`reset_announce` - resets announce to use test adapter, prefix, app, and logging to `/dev/null`
|
340
|
+
|
305
341
|
### Developing an Adapter Class
|
306
342
|
|
307
343
|
Adapter classes should be named with the following module structure: `Announce::Adapters::SomeBrokerAdapter`
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'announce'
|
2
|
+
require 'announce/adapters/test_adapter'
|
3
|
+
|
4
|
+
module Announce
|
5
|
+
module Testing
|
6
|
+
|
7
|
+
def published_messages
|
8
|
+
Announce::Adapters::TestAdapter::Topic.published_messages
|
9
|
+
end
|
10
|
+
|
11
|
+
def last_message
|
12
|
+
published_messages.last
|
13
|
+
end
|
14
|
+
|
15
|
+
def clear_messages
|
16
|
+
published_messages.clear
|
17
|
+
end
|
18
|
+
|
19
|
+
def subscriptions
|
20
|
+
Announce::Adapters::TestAdapter::Subscriber.subscriptions
|
21
|
+
end
|
22
|
+
|
23
|
+
def last_subscription
|
24
|
+
subscriptions.last
|
25
|
+
end
|
26
|
+
|
27
|
+
def clear_subscriptions
|
28
|
+
subscriptions.clear
|
29
|
+
end
|
30
|
+
|
31
|
+
def broker_configured?
|
32
|
+
Announce::Adapters::TestAdapter::BrokerManager.configured?
|
33
|
+
end
|
34
|
+
|
35
|
+
def reset_broker_config
|
36
|
+
Announce::Adapters::TestAdapter::BrokerManager.reset
|
37
|
+
end
|
38
|
+
|
39
|
+
def reset_announce
|
40
|
+
Announce.logger = Logger.new('/dev/null')
|
41
|
+
Announce.options[:adapter] = 'test'
|
42
|
+
Announce.options[:queue_name_prefix] = 'test'
|
43
|
+
Announce.options[:app_name] = 'app'
|
44
|
+
clear_messages
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/announce/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: announce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kuklewicz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoryuken
|
@@ -181,6 +181,7 @@ files:
|
|
181
181
|
- lib/announce/publisher.rb
|
182
182
|
- lib/announce/railtie.rb
|
183
183
|
- lib/announce/subscriber.rb
|
184
|
+
- lib/announce/testing.rb
|
184
185
|
- lib/announce/version.rb
|
185
186
|
- lib/tasks/announce.rake
|
186
187
|
homepage: https://github.com/PRX/announce
|