message_bus 1.1.1 → 2.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of message_bus might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG +8 -0
- data/README.md +49 -8
- data/assets/message-bus.js +111 -25
- data/examples/chat/chat.rb +2 -0
- data/examples/chat/docker_container/chat.yml +22 -10
- data/examples/chat/docker_container/update_chat +2 -2
- data/lib/message_bus.rb +10 -13
- data/lib/message_bus/client.rb +105 -27
- data/lib/message_bus/connection_manager.rb +10 -27
- data/lib/message_bus/rack/middleware.rb +29 -8
- data/lib/message_bus/rails/railtie.rb +6 -3
- data/lib/message_bus/version.rb +1 -1
- data/spec/lib/fake_async_middleware.rb +7 -0
- data/spec/lib/{assets → message_bus/assets}/asset_encoding_spec.rb +1 -1
- data/spec/lib/{client_spec.rb → message_bus/client_spec.rb} +78 -0
- data/spec/lib/{connection_manager_spec.rb → message_bus/connection_manager_spec.rb} +0 -0
- data/spec/lib/{multi_process_spec.rb → message_bus/multi_process_spec.rb} +0 -0
- data/spec/lib/{middleware_spec.rb → message_bus/rack/middleware_spec.rb} +2 -89
- data/spec/lib/{redis → message_bus/redis}/reliable_pub_sub_spec.rb +4 -3
- data/spec/lib/{timer_thread_spec.rb → message_bus/timer_thread_spec.rb} +6 -22
- data/spec/spec_helper.rb +6 -1
- data/vendor/assets/javascripts/message-bus.js +111 -25
- metadata +19 -24
- data/lib/message_bus/message_handler.rb +0 -26
- data/spec/lib/handlers/demo_message_handler.rb +0 -5
- data/spec/lib/message_handler_spec.rb +0 -39
@@ -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,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
|