Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #20 from endel/wildcard-monitoring

Support wildcard monitoring. (issue #18)
  • Loading branch information...
commit 2dfd1ac928422f8cc50f0d506b32679e5de24a65 2 parents dd8802d + 8080cf0
James Harton authored
View
4 lib/faye-rails/controller/channel.rb
@@ -25,7 +25,7 @@ def monitor(event, &block)
m.client_id = args.shift
m.channel = args.shift
m.data = args.shift
- m.instance_eval(&block) if m.channel == channel
+ m.instance_eval(&block) if File.fnmatch(channel, m.channel)
end
end
end
@@ -39,7 +39,7 @@ def filter(direction=:any, &block)
end
def subscribe(&block)
- EM.schedule do
+ EM.schedule do
@subscription = FayeRails.client(endpoint).subscribe(channel) do |message|
Message.new.tap do |m|
m.message = message
View
21 spec/lib/faye-rails/controller_spec.rb
@@ -48,7 +48,7 @@
Fiber.yield.should == 'timeout'
end.resume
end
-
+
it "should be able to subscribe to multiple channels" do
2.upto(10).each do |i|
Fiber.new do
@@ -120,6 +120,25 @@
end
end
+ it "should be able to monitor wildcard channels" do
+ Fiber.new do
+ this_fiber = Fiber.current
+ controller.channel('/widgets/*') do
+ monitor :publish do
+ this_fiber.resume message
+ end
+ end
+ EM.schedule do
+ FayeRails.client.publish('/widgets/20', "Rosey, bring me a beer!")
+ end
+ EM.add_timer 5 do
+ this_fiber.resume "timeout"
+ end
+ Fiber.yield.should == "Rosey, bring me a beer!"
+ end
+ end
+
+
end
describe WidgetController do
Please sign in to comment.
Something went wrong with that request. Please try again.