attention 0.0.4 → 0.0.5
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/attention.rb +1 -0
- data/lib/attention/blocking_subscriber.rb +50 -0
- data/lib/attention/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: d854a64d0631d2acc718ee5d310ee1e492e2e2cf
|
4
|
+
data.tar.gz: c4403ff3290f181ff6f1f7f5fd63225ee54def8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91daaa57e01146e683e8fba37fd3c94c5b1a868ef7602f5aacbdf2ab57397ffd9c1a2f66caab2fc0d4f6d966d45467f55d4c35956e4ccfb3c97c503bc9497fcc
|
7
|
+
data.tar.gz: dd233e7e2ee479f9f87d0cc361de3c0f4d5fb9865970dfb7668460e42d80f970e35450a1c5aca0823d87995bdda8ef29cbba33ed3d72f88dc73a80c4d921d59d
|
data/lib/attention.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'attention/connection'
|
3
|
+
require 'attention/publisher'
|
4
|
+
|
5
|
+
module Attention
|
6
|
+
# Uses Redis pub/sub to synchronously respond to events
|
7
|
+
#
|
8
|
+
# Each Subscriber uses a Redis connection to listen to a channel for events.
|
9
|
+
class BlockingSubscriber
|
10
|
+
# The channel subscribed to
|
11
|
+
attr_reader :channel
|
12
|
+
|
13
|
+
# @!visibility private
|
14
|
+
attr_reader :redis
|
15
|
+
|
16
|
+
# Creates a subscription to the given channel
|
17
|
+
# @param channel [String] The channel to listen to
|
18
|
+
# @yield The code to execute on a published event
|
19
|
+
# @yieldparam channel [String] The channel the subscriber is listening to
|
20
|
+
# @yieldparam data [Object] The event published on the channel
|
21
|
+
# @yieldparam subscriber [BlockingSubscriber] This instance
|
22
|
+
def initialize(channel, &callback)
|
23
|
+
@channel = channel
|
24
|
+
@redis = Connection.new
|
25
|
+
subscribe &callback
|
26
|
+
end
|
27
|
+
|
28
|
+
# Sets up the Redis pub/sub subscription
|
29
|
+
# @yield The code to execute on a published event
|
30
|
+
def subscribe(&callback)
|
31
|
+
redis.subscribe(channel) do |on|
|
32
|
+
on.message do |channel, payload|
|
33
|
+
data = JSON.parse(payload) rescue payload
|
34
|
+
callback.call channel, data, self
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# The {Publisher} used to send the unsubscribe message
|
40
|
+
# @api private
|
41
|
+
def publisher
|
42
|
+
@publisher ||= Publisher.new
|
43
|
+
end
|
44
|
+
|
45
|
+
# Unsubscribes from the channel
|
46
|
+
def unsubscribe
|
47
|
+
redis.unsubscribe
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/attention/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attention
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Parrish
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- bin/setup
|
186
186
|
- examples/awareness.rb
|
187
187
|
- lib/attention.rb
|
188
|
+
- lib/attention/blocking_subscriber.rb
|
188
189
|
- lib/attention/connection.rb
|
189
190
|
- lib/attention/instance.rb
|
190
191
|
- lib/attention/publisher.rb
|