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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 557dce7bb9c5e9cc8a58b6200ee538e7464cb643
4
- data.tar.gz: ee5d2428c3aa6ee5d8bb163d86f79c1e7c37155b
3
+ metadata.gz: c8e3bd526a5467ef4743ae56b53494580dcdb2f1
4
+ data.tar.gz: 56214dcdc3e9dcd228724e986c118e64f8ff4bd8
5
5
  SHA512:
6
- metadata.gz: 6577992017a7aa57349c0b1f29ebc1c9c942df78ed77400285674bacaf141ac97cab50465f201fb5b7411c9db07b1108a7042c0e790e40aa9f5e06f285386e95
7
- data.tar.gz: f6d714360eb9d0c73fadb36cec04adcab8663a43bda48c2300535d5a16da53061f0d604ed34d2bd238920f3a6928c35f65b9b967ca98054a1f0abbab210275ea
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
- # The `as: :events` is optional, but will generate a named route for events_path
26
- mount Pubsubstub::Application.new, at: "/events", as: :events
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
- mount Pubsubstub::StreamAction.new, at: "/events", as: :events
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
- mount UserRequiredMiddleware.new(Pubsubstub::StreamAction.new), at: "/events", as: :events
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
- require 'pubsubstub'
50
+ ```ruby
51
+ require 'pubsubstub'
45
52
 
46
- run Pubsubstub::Application
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
 
@@ -1,5 +1,11 @@
1
1
  module Pubsubstub
2
+ class << self
3
+ attr_accessor :heartbeat_frequency
4
+ end
5
+ self.heartbeat_frequency = 15
6
+
2
7
  class Application < Sinatra::Base
8
+
3
9
  use PublishAction
4
10
  use StreamAction
5
11
  end
@@ -31,9 +31,10 @@ module Pubsubstub
31
31
  private
32
32
  def start_heartbeat
33
33
  @heartbeat = Thread.new do
34
- while true
35
- sleep 15
36
- @connections.each { |connection| connection << "\n" }
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
@@ -1,3 +1,3 @@
1
1
  module Pubsubstub
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.9"
3
3
  end
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 be_true
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 be_true
46
+ expect(subject.subscribed?(connection)).to be true
47
47
  subject.unsubscribe(connection)
48
- expect(subject.subscribed?(connection)).to be_false
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.7
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: 2014-05-18 00:00:00.000000000 Z
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: