Skip to content
This repository has been archived by the owner on May 25, 2018. It is now read-only.

Commit

Permalink
Merge pull request #20 from endel/wildcard-monitoring
Browse files Browse the repository at this point in the history
Support wildcard monitoring. (issue #18)
  • Loading branch information
James Harton committed Oct 16, 2012
2 parents dd8802d + 8080cf0 commit 2dfd1ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/faye-rails/controller/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 20 additions & 1 deletion spec/lib/faye-rails/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2dfd1ac

Please sign in to comment.