meerkat 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/app.rb +0 -1
- data/examples/config.ru +2 -2
- data/examples/views/index.haml +44 -44
- data/lib/meerkat/backend/redis.rb +3 -3
- data/lib/meerkat/rackadapter.rb +1 -1
- data/lib/meerkat/version.rb +1 -1
- metadata +22 -22
data/examples/app.rb
CHANGED
data/examples/config.ru
CHANGED
@@ -3,8 +3,8 @@ require 'meerkat'
|
|
3
3
|
require './app'
|
4
4
|
|
5
5
|
#Meerkat.backend = Meerkat::Backend::InMemory.new
|
6
|
-
|
7
|
-
Meerkat.backend = Meerkat::Backend::PG.new :dbname => 'postgres'
|
6
|
+
Meerkat.backend = Meerkat::Backend::Redis.new
|
7
|
+
#Meerkat.backend = Meerkat::Backend::PG.new :dbname => 'postgres'
|
8
8
|
map '/' do
|
9
9
|
run App
|
10
10
|
end
|
data/examples/views/index.haml
CHANGED
@@ -1,52 +1,52 @@
|
|
1
1
|
!!!
|
2
|
-
%
|
3
|
-
%
|
4
|
-
|
5
|
-
%
|
6
|
-
%
|
7
|
-
%
|
8
|
-
|
9
|
-
%
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title Meerkat test
|
5
|
+
%script{:src=>'https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js', :type => 'text/javascript'}
|
6
|
+
%body
|
7
|
+
%fieldset
|
8
|
+
%legend Publish
|
9
|
+
%form#pub{:method => :post}
|
10
|
+
%label
|
11
|
+
Topic:
|
12
|
+
%input{:name => 'topic', :value => 'foo'}
|
13
|
+
%label
|
14
|
+
Message:
|
15
|
+
%input{:name => 'message'}
|
16
|
+
%input{:type => 'submit', :value => 'Send'}
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
%fieldset
|
19
|
+
%legend Subscribe
|
20
|
+
%label
|
21
|
+
Subscribe to
|
22
|
+
%input#sub_topic{:name => 'topic', :value => 'foo'}
|
23
|
+
%input#start_subscribe{:type => 'submit', :value => 'Start!'}
|
23
24
|
|
24
|
-
|
25
|
+
%ul#stream
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
27
|
+
:javascript
|
28
|
+
var source;
|
29
|
+
function subscribe_to(topic) {
|
30
|
+
if (source != null) { source.close() }
|
31
|
+
source = new EventSource('/stream/' + topic)
|
32
|
+
var stream = document.getElementById('stream')
|
33
|
+
source.onmessage = function(e) {
|
34
|
+
var li = document.createElement('li')
|
35
|
+
li.innerHTML = JSON.parse(e.data)
|
36
|
+
stream.appendChild(li)
|
37
|
+
}
|
37
38
|
}
|
38
|
-
}
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
$(function() {
|
41
|
+
$("#pub").submit(function() {
|
42
|
+
$.post(this.action, $(this).serialize())
|
43
|
+
return false
|
44
|
+
});
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
$("#start_subscribe").click(function() {
|
47
|
+
subscribe_to($("#sub_topic").val())
|
48
|
+
return false
|
49
|
+
});
|
50
50
|
|
51
|
-
|
52
|
-
|
51
|
+
subscribe_to($("#sub_topic").val())
|
52
|
+
})
|
@@ -8,6 +8,9 @@ module Meerkat
|
|
8
8
|
EM.next_tick do
|
9
9
|
@sub = EM::Hiredis.connect redis_uri
|
10
10
|
@pub = EM::Hiredis.connect redis_uri
|
11
|
+
@sub.on :pmessage do |topic, channel, message|
|
12
|
+
@subs[topic].each { |cb| cb.call channel, message }
|
13
|
+
end
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
@@ -22,9 +25,6 @@ module Meerkat
|
|
22
25
|
@subs[topic] = [ callback ]
|
23
26
|
EM.next_tick do
|
24
27
|
@sub.psubscribe topic
|
25
|
-
@sub.on :pmessage do |topic, channel, message|
|
26
|
-
@subs[topic].each { |cb| cb.call channel, message }
|
27
|
-
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
[topic, callback]
|
data/lib/meerkat/rackadapter.rb
CHANGED
@@ -25,7 +25,7 @@ module Meerkat
|
|
25
25
|
|
26
26
|
path_info = Rack::Utils.unescape env["PATH_INFO"]
|
27
27
|
sub = Meerkat.subscribe(path_info) do |topic, json|
|
28
|
-
body << "event: #{topic}\n"
|
28
|
+
body << "event: #{topic}\n" unless path_info == topic
|
29
29
|
body << "data: #{json}\n\n"
|
30
30
|
end
|
31
31
|
body.errback do
|
data/lib/meerkat/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meerkat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
16
|
-
requirement: &
|
16
|
+
requirement: &70174238921400 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70174238921400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rack-test
|
27
|
-
requirement: &
|
27
|
+
requirement: &70174238920780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70174238920780
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: thin_async
|
38
|
-
requirement: &
|
38
|
+
requirement: &70174238920140 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70174238920140
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: thin-async-test
|
49
|
-
requirement: &
|
49
|
+
requirement: &70174238919320 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70174238919320
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: em-minitest-spec
|
60
|
-
requirement: &
|
60
|
+
requirement: &70174238918880 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70174238918880
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yajl-ruby
|
71
|
-
requirement: &
|
71
|
+
requirement: &70174238918400 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70174238918400
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: eventmachine
|
82
|
-
requirement: &
|
82
|
+
requirement: &70174238914700 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70174238914700
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: em-hiredis
|
93
|
-
requirement: &
|
93
|
+
requirement: &70174238914060 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70174238914060
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: pg
|
104
|
-
requirement: &
|
104
|
+
requirement: &70174238913360 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70174238913360
|
113
113
|
description: Requires an evented Ruby dispatcher, like Thin
|
114
114
|
email:
|
115
115
|
- carl.hoerberg@gmail.com
|
@@ -151,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
151
|
version: '0'
|
152
152
|
segments:
|
153
153
|
- 0
|
154
|
-
hash:
|
154
|
+
hash: 2628710167676549953
|
155
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
156
|
none: false
|
157
157
|
requirements:
|
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
160
|
version: '0'
|
161
161
|
segments:
|
162
162
|
- 0
|
163
|
-
hash:
|
163
|
+
hash: 2628710167676549953
|
164
164
|
requirements: []
|
165
165
|
rubyforge_project: meerkat
|
166
166
|
rubygems_version: 1.8.6
|