juggernaut 2.0.0.beta2 → 2.0.0.beta3

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta2
1
+ 2.0.0.beta3
@@ -0,0 +1,10 @@
1
+ clients = {}
2
+
3
+ Juggernaut.subscribe do |event, data|
4
+ case event
5
+ when :subscribe
6
+ clients[data.session_id] = data
7
+ when :unsubscribe
8
+ clients.delete(data.session_id)
9
+ end
10
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{juggernaut}
8
- s.version = "2.0.0.beta2"
8
+ s.version = "2.0.0.beta3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex MacCaw"]
12
- s.date = %q{2010-09-10}
12
+ s.date = %q{2010-09-16}
13
13
  s.description = %q{Use Juggernaut to easily implement realtime chat, collaboration, gaming and much more!}
14
14
  s.email = %q{info@eribium.org}
15
15
  s.extra_rdoc_files = [
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  "VERSION",
24
24
  "examples/juggernaut_observer.js",
25
25
  "examples/juggernaut_observer.rb",
26
+ "examples/roster.rb",
26
27
  "juggernaut.gemspec",
27
28
  "lib/juggernaut.rb"
28
29
  ]
@@ -2,18 +2,31 @@ require "redis"
2
2
  require "json"
3
3
 
4
4
  module Juggernaut
5
- def redis
6
- @redis ||= Redis.new
5
+ def redis_options
6
+ @redis_options ||= {}
7
7
  end
8
8
 
9
- def redis=(val)
10
- @redis = val
11
- end
12
-
13
9
  def publish(channels, data, options = {})
14
- message = ({:channels => Array(channels), :data => data}).merge(options)
15
- redis.publish(:juggernaut, message.to_json)
10
+ message = ({:channels => Array(channels).uniq, :data => data}).merge(options)
11
+ redis.publish(key, message.to_json)
12
+ end
13
+
14
+ def subscribe
15
+ Redis.new(redis_options).subscribe(key(:subscribe), key(:unsubscribe)) do |on|
16
+ on.message do |type, msg|
17
+ yield(type.gsub(/^juggernaut:/, "").to_sym, JSON.parse(msg))
18
+ end
19
+ end
16
20
  end
21
+
22
+ protected
23
+ def redis
24
+ @redis ||= Redis.new(redis_options)
25
+ end
26
+
27
+ def key(*args)
28
+ args.unshift(:juggernaut).join(":")
29
+ end
17
30
 
18
- extend self
31
+ extend self
19
32
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 2
7
7
  - 0
8
8
  - 0
9
- - beta2
10
- version: 2.0.0.beta2
9
+ - beta3
10
+ version: 2.0.0.beta3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex MacCaw
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-10 00:00:00 +01:00
18
+ date: 2010-09-16 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -47,6 +47,7 @@ files:
47
47
  - VERSION
48
48
  - examples/juggernaut_observer.js
49
49
  - examples/juggernaut_observer.rb
50
+ - examples/roster.rb
50
51
  - juggernaut.gemspec
51
52
  - lib/juggernaut.rb
52
53
  has_rdoc: true