pubsubstub 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8550c78aff6963d9bac3a9665518f6ee0aec9dc
4
+ data.tar.gz: fea96f48f595f51acc4aa5b4b3fa5e15681ff968
5
+ SHA512:
6
+ metadata.gz: dd2bc2f598f12007319a20c1943a4ade7ef39c27479fac1c0b1db61a85c6d5e670cd88b365f5f7249cf2ce679db6e854f5cd188709dff8dff47f53a71519f251
7
+ data.tar.gz: 1c128dd712f5dbbeb5e5f285502b897f583e9b21cb8d0dc9fcbf58fb1826e341c4ac554f37dc8ad66877fc626de1c4c74d38d3db568c8ad61c2077825ac44b68
data/README.md CHANGED
@@ -22,7 +22,20 @@ Or install it yourself as:
22
22
 
23
23
  ### Rails
24
24
 
25
- match "/events", to: Pubsubstub::Application, via: :all
25
+ # The `as: :events` is optional, but will generate a named route for events_path
26
+ mount Pubsubstub::Application.new, at: "/events", as: :events
27
+
28
+ You can also cherry-pick actions. For example, if you don't want to publish through HTTP:
29
+
30
+ mount Pubsubstub::StreamAction.new, at: "/events", as: :events
31
+
32
+ This will allow you to mount a publish action in the admin, or leave it out completely.
33
+
34
+ ### Authentication
35
+
36
+ Need authentication? No problem! Load a Rack middleware in front of Pubsubstub to do the job!
37
+
38
+ mount UserRequiredMiddleware.new(Pubsubstub::StreamAction.new), at: "/events", as: :events
26
39
 
27
40
  ### Standalone
28
41
 
@@ -0,0 +1,17 @@
1
+ module Pubsubstub
2
+ class Action < Sinatra::Base
3
+ configure :production, :development do
4
+ enable :logging
5
+ end
6
+
7
+ def initialize(*)
8
+ @channels = Hash.new { |h, k| h[k] = Channel.new(k) }
9
+ @connections = []
10
+ super
11
+ end
12
+
13
+ def channel(name)
14
+ @channels[name]
15
+ end
16
+ end
17
+ end
@@ -1,48 +1,6 @@
1
1
  module Pubsubstub
2
2
  class Application < Sinatra::Base
3
- configure :production, :development do
4
- enable :logging
5
- end
6
-
7
- def initialize
8
- @channels = Hash.new { |h, k| h[k] = Channel.new(k) }
9
- @connections = []
10
- super
11
- end
12
-
13
- def channel(name)
14
- @channels[name]
15
- end
16
-
17
- get '/', provides: 'text/event-stream' do
18
- status(200)
19
- headers({
20
- 'Cache-Control' => 'no-cache',
21
- 'X-Accel-Buffering' => 'no',
22
- 'Connection' => 'keep-alive',
23
- })
24
- stream(:keep_open) do |connection|
25
- @connections << connection
26
- channels = params[:channels] || [:default]
27
- channels.each do |channel_name|
28
- channel(channel_name).subscribe(connection, last_event_id: request.env['HTTP_LAST_EVENT_ID'])
29
- end
30
-
31
- connection.callback do
32
- @connections.delete(connection)
33
- channels.each do |channel_name|
34
- channel(channel_name).unsubscribe(connection)
35
- end
36
- end
37
- end
38
- end
39
-
40
- post '/' do
41
- event = Event.new(params[:data], name: params[:event])
42
- (params[:channels] || [:default]).each do |channel_name|
43
- channel(channel_name).publish(event)
44
- end
45
- ""
46
- end
3
+ use PublishAction
4
+ use StreamAction
47
5
  end
48
6
  end
@@ -0,0 +1,11 @@
1
+ module Pubsubstub
2
+ class PublishAction < Pubsubstub::Action
3
+ post '/' do
4
+ event = Event.new(params[:data], name: params[:event])
5
+ (params[:channels] || [:default]).each do |channel_name|
6
+ channel(channel_name).publish(event)
7
+ end
8
+ ""
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ module Pubsubstub
2
+ class StreamAction < Pubsubstub::Action
3
+ get '/', provides: 'text/event-stream' do
4
+ status(200)
5
+ headers({
6
+ 'Cache-Control' => 'no-cache',
7
+ 'X-Accel-Buffering' => 'no',
8
+ 'Connection' => 'keep-alive',
9
+ })
10
+ stream(:keep_open) do |connection|
11
+ @connections << connection
12
+ channels = params[:channels] || [:default]
13
+ channels.each do |channel_name|
14
+ channel(channel_name).subscribe(connection, last_event_id: request.env['HTTP_LAST_EVENT_ID'])
15
+ end
16
+
17
+ connection.callback do
18
+ @connections.delete(connection)
19
+ channels.each do |channel_name|
20
+ channel(channel_name).unsubscribe(connection)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Pubsubstub
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/pubsubstub.rb CHANGED
@@ -6,5 +6,8 @@ require "pubsubstub/version"
6
6
  require "pubsubstub/redis_pub_sub"
7
7
  require "pubsubstub/channel"
8
8
  require "pubsubstub/event"
9
+ require "pubsubstub/action"
10
+ require "pubsubstub/stream_action"
11
+ require "pubsubstub/publish_action"
9
12
  require "pubsubstub/application"
10
13
 
metadata CHANGED
@@ -1,158 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubsubstub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 0.0.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Guillaume Malette
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-04-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: sinatra
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.4'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.4'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: em-hiredis
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0.2'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0.2'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: redis
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '3.0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '3.0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: eventmachine
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: '1.0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: '1.0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: bundler
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ~>
73
+ - - "~>"
84
74
  - !ruby/object:Gem::Version
85
75
  version: '1.5'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ~>
80
+ - - "~>"
92
81
  - !ruby/object:Gem::Version
93
82
  version: '1.5'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rake
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ~>
87
+ - - "~>"
100
88
  - !ruby/object:Gem::Version
101
89
  version: '10.2'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ~>
94
+ - - "~>"
108
95
  - !ruby/object:Gem::Version
109
96
  version: '10.2'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: rspec
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ~>
101
+ - - "~>"
116
102
  - !ruby/object:Gem::Version
117
103
  version: '2.14'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ~>
108
+ - - "~>"
124
109
  - !ruby/object:Gem::Version
125
110
  version: '2.14'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: pry
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ~>
115
+ - - "~>"
132
116
  - !ruby/object:Gem::Version
133
117
  version: '0.9'
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ~>
122
+ - - "~>"
140
123
  - !ruby/object:Gem::Version
141
124
  version: '0.9'
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: thin
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
- - - ~>
129
+ - - "~>"
148
130
  - !ruby/object:Gem::Version
149
131
  version: '1.6'
150
132
  type: :development
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
- - - ~>
136
+ - - "~>"
156
137
  - !ruby/object:Gem::Version
157
138
  version: '1.6'
158
139
  description: Pubsubstub can be added to a rack Application or deployed standalone.
@@ -163,18 +144,21 @@ executables: []
163
144
  extensions: []
164
145
  extra_rdoc_files: []
165
146
  files:
166
- - .gitignore
167
- - .rspec
168
- - .travis.yml
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".travis.yml"
169
150
  - Gemfile
170
151
  - LICENSE.txt
171
152
  - README.md
172
153
  - Rakefile
173
154
  - lib/pubsubstub.rb
155
+ - lib/pubsubstub/action.rb
174
156
  - lib/pubsubstub/application.rb
175
157
  - lib/pubsubstub/channel.rb
176
158
  - lib/pubsubstub/event.rb
159
+ - lib/pubsubstub/publish_action.rb
177
160
  - lib/pubsubstub/redis_pub_sub.rb
161
+ - lib/pubsubstub/stream_action.rb
178
162
  - lib/pubsubstub/version.rb
179
163
  - pubsubstub.gemspec
180
164
  - spec/channel_spec.rb
@@ -184,30 +168,30 @@ files:
184
168
  homepage: https://github.com/gmalette/pubsubstub
185
169
  licenses:
186
170
  - MIT
171
+ metadata: {}
187
172
  post_install_message:
188
173
  rdoc_options: []
189
174
  require_paths:
190
175
  - lib
191
176
  required_ruby_version: !ruby/object:Gem::Requirement
192
- none: false
193
177
  requirements:
194
- - - ! '>='
178
+ - - ">="
195
179
  - !ruby/object:Gem::Version
196
180
  version: '0'
197
181
  required_rubygems_version: !ruby/object:Gem::Requirement
198
- none: false
199
182
  requirements:
200
- - - ! '>='
183
+ - - ">="
201
184
  - !ruby/object:Gem::Version
202
185
  version: '0'
203
186
  requirements: []
204
187
  rubyforge_project:
205
- rubygems_version: 1.8.23
188
+ rubygems_version: 2.2.2
206
189
  signing_key:
207
- specification_version: 3
190
+ specification_version: 4
208
191
  summary: Pubsubstub is a rack middleware to add Pub/Sub
209
192
  test_files:
210
193
  - spec/channel_spec.rb
211
194
  - spec/event_spec.rb
212
195
  - spec/redis_pub_sub_spec.rb
213
196
  - spec/spec_helper.rb
197
+ has_rdoc: