pubsubstub 0.0.7 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -6
- data/lib/pubsubstub/application.rb +6 -0
- data/lib/pubsubstub/stream_action.rb +4 -3
- data/lib/pubsubstub/version.rb +1 -1
- data/spec/channel_spec.rb +3 -3
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8e3bd526a5467ef4743ae56b53494580dcdb2f1
|
4
|
+
data.tar.gz: 56214dcdc3e9dcd228724e986c118e64f8ff4bd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe3f0a3d0476c7efdb9e1d1e970e621a10dd4a26011f4cd3032952fa0b5b9f0c818fea9bf0b8f26f9c932b20bc759cc1aee726ee20739fc590cf329bb47b4632
|
7
|
+
data.tar.gz: a0683e93134dff4296d28cb41b8f4e979c67fd7dc86a8db82aef765b66a91c5f7b537c5ecd4e3231dad35091c004393246f0855b6b3355b63dc78585e5fee44d
|
data/README.md
CHANGED
@@ -22,12 +22,16 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
### Rails
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
```ruby
|
26
|
+
# The `as: :events` is optional, but will generate a named route for events_path
|
27
|
+
mount Pubsubstub::Application.new, at: "/events", as: :events
|
28
|
+
```
|
27
29
|
|
28
30
|
You can also cherry-pick actions. For example, if you don't want to publish through HTTP:
|
29
31
|
|
30
|
-
|
32
|
+
```ruby
|
33
|
+
mount Pubsubstub::StreamAction.new, at: "/events", as: :events
|
34
|
+
```
|
31
35
|
|
32
36
|
This will allow you to mount a publish action in the admin, or leave it out completely.
|
33
37
|
|
@@ -35,15 +39,27 @@ This will allow you to mount a publish action in the admin, or leave it out comp
|
|
35
39
|
|
36
40
|
Need authentication? No problem! Load a Rack middleware in front of Pubsubstub to do the job!
|
37
41
|
|
38
|
-
|
42
|
+
```ruby
|
43
|
+
mount UserRequiredMiddleware.new(Pubsubstub::StreamAction.new), at: "/events", as: :events
|
44
|
+
```
|
39
45
|
|
40
46
|
### Standalone
|
41
47
|
|
42
48
|
You can easily run Pubsubstub standalone by creating a `config.ru` file containing
|
43
49
|
|
44
|
-
|
50
|
+
```ruby
|
51
|
+
require 'pubsubstub'
|
45
52
|
|
46
|
-
|
53
|
+
run Pubsubstub::Application
|
54
|
+
```
|
55
|
+
|
56
|
+
### Sending an event
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
payload = user.to_json
|
60
|
+
event = Pubsubstub::Event.new(payload, name: "user.update")
|
61
|
+
Pubsubstub::RedisPubSub.publish("user.#{user_id}", event)
|
62
|
+
```
|
47
63
|
|
48
64
|
To start the application, run `bundle exec thin start --timeout 0 --max-conns 1024`
|
49
65
|
|
@@ -31,9 +31,10 @@ module Pubsubstub
|
|
31
31
|
private
|
32
32
|
def start_heartbeat
|
33
33
|
@heartbeat = Thread.new do
|
34
|
-
|
35
|
-
sleep
|
36
|
-
|
34
|
+
loop do
|
35
|
+
sleep Pubsubstub.heartbeat_frequency
|
36
|
+
event = Event.new('ping', name: 'heartbeat').to_message
|
37
|
+
@connections.each { |connection| connection << event }
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
data/lib/pubsubstub/version.rb
CHANGED
data/spec/channel_spec.rb
CHANGED
@@ -16,7 +16,7 @@ describe Pubsubstub::Channel do
|
|
16
16
|
let(:connection) { double('connection') }
|
17
17
|
it "subscribes the client" do
|
18
18
|
subject.subscribe(connection)
|
19
|
-
expect(subject.subscribed?(connection)).to
|
19
|
+
expect(subject.subscribed?(connection)).to be true
|
20
20
|
end
|
21
21
|
|
22
22
|
it "starts subscribing to the channel if it's the first client" do
|
@@ -43,9 +43,9 @@ describe Pubsubstub::Channel do
|
|
43
43
|
before { subject.subscribe(connection) }
|
44
44
|
|
45
45
|
it "unsubscribes the client" do
|
46
|
-
expect(subject.subscribed?(connection)).to
|
46
|
+
expect(subject.subscribed?(connection)).to be true
|
47
47
|
subject.unsubscribe(connection)
|
48
|
-
expect(subject.subscribed?(connection)).to
|
48
|
+
expect(subject.subscribed?(connection)).to be false
|
49
49
|
end
|
50
50
|
|
51
51
|
it "does not stop listening if it's not the last client" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pubsubstub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume Malette
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -194,4 +194,3 @@ test_files:
|
|
194
194
|
- spec/event_spec.rb
|
195
195
|
- spec/redis_pub_sub_spec.rb
|
196
196
|
- spec/spec_helper.rb
|
197
|
-
has_rdoc:
|