message_bus 1.1.1 → 2.0.0.beta.1

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.

Potentially problematic release.


This version of message_bus might be problematic. Click here for more details.

@@ -1,26 +0,0 @@
1
- class MessageBus::MessageHandler
2
- def self.load_handlers(path)
3
- Dir.glob("#{path}/*.rb").each do |f|
4
- load "#{f}"
5
- end
6
- end
7
-
8
- def self.handle(name,&blk)
9
- raise ArgumentError.new("expecting block") unless block_given?
10
- raise ArgumentError.new("name") unless name
11
-
12
- @@handlers ||= {}
13
- @@handlers[name] = blk
14
- end
15
-
16
- def self.call(site_id, name, data, current_user_id)
17
- begin
18
- MessageBus.on_connect.call(site_id) if MessageBus.on_connect
19
- @@handlers[name].call(data,current_user_id)
20
- ensure
21
- MessageBus.on_disconnect.call(site_id) if MessageBus.on_disconnect
22
- end
23
- end
24
-
25
-
26
- end
@@ -1,5 +0,0 @@
1
- class DemoMessageHandler < MessageBus::MessageHandler
2
- handle "/dupe" do |m, uid|
3
- "#{m}#{m}"
4
- end
5
- end
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
- require 'message_bus'
3
-
4
- describe MessageBus::MessageHandler do
5
-
6
- it "should properly register message handlers" do
7
- MessageBus::MessageHandler.handle "/hello" do |m|
8
- m
9
- end
10
- MessageBus::MessageHandler.call("site","/hello", "world", 1).should == "world"
11
- end
12
-
13
- it "should correctly load message handlers" do
14
- MessageBus::MessageHandler.load_handlers("#{File.dirname(__FILE__)}/handlers")
15
- MessageBus::MessageHandler.call("site","/dupe", "1", 1).should == "11"
16
- end
17
-
18
- it "should allow for a connect / disconnect callback" do
19
- MessageBus::MessageHandler.handle "/channel" do |m|
20
- m
21
- end
22
-
23
- connected = false
24
- disconnected = false
25
-
26
- MessageBus.on_connect do |site_id|
27
- connected = true
28
- end
29
- MessageBus.on_disconnect do |site_id|
30
- disconnected = true
31
- end
32
-
33
- MessageBus::MessageHandler.call("site_id", "/channel", "data", 1)
34
-
35
- connected.should == true
36
- disconnected.should == true
37
-
38
- end
39
- end