Class: FayeRails::Controller::Channel
- Inherits:
-
Object
- Object
- FayeRails::Controller::Channel
- Defined in:
- lib/faye-rails/controller/channel.rb
Instance Attribute Summary (collapse)
-
- (Object) channel
readonly
Returns the value of attribute channel.
-
- (Object) endpoint
readonly
Returns the value of attribute endpoint.
Instance Method Summary (collapse)
- - (Object) client
- - (Object) filter(direction = :any, &block)
-
- (Channel) initialize(channel, endpoint = nil)
constructor
A new instance of Channel.
- - (Object) monitor(event, &block)
- - (Object) publish(message)
- - (Object) subscribe(&block)
- - (Object) unsubscribe
Constructor Details
- (Channel) initialize(channel, endpoint = nil)
A new instance of Channel
7 8 9 10 |
# File 'lib/faye-rails/controller/channel.rb', line 7 def initialize(channel, endpoint=nil) @channel = channel @endpoint = endpoint end |
Instance Attribute Details
- (Object) channel (readonly)
Returns the value of attribute channel
5 6 7 |
# File 'lib/faye-rails/controller/channel.rb', line 5 def channel @channel end |
- (Object) endpoint (readonly)
Returns the value of attribute endpoint
5 6 7 |
# File 'lib/faye-rails/controller/channel.rb', line 5 def endpoint @endpoint end |
Instance Method Details
- (Object) client
12 13 14 |
# File 'lib/faye-rails/controller/channel.rb', line 12 def client FayeRails.client(endpoint) end |
- (Object) filter(direction = :any, &block)
33 34 35 36 37 38 39 |
# File 'lib/faye-rails/controller/channel.rb', line 33 def filter(direction=:any, &block) filter = FayeRails::Filter.new(channel, direction, block) server = FayeRails.server(endpoint) server.add_extension(filter) filter.server = server filter end |
- (Object) monitor(event, &block)
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/faye-rails/controller/channel.rb', line 20 def monitor(event, &block) raise ArgumentError, "Unknown event #{event.inspect}" unless [:subscribe,:unsubscribe,:publish].member? event FayeRails.server(endpoint).bind(event) do |*args| Monitor.new.tap do |m| m.client_id = args.shift m.channel = args.shift m.data = args.shift m.instance_eval(&block) if File.fnmatch(channel, m.channel) end end end |
- (Object) publish(message)
16 17 18 |
# File 'lib/faye-rails/controller/channel.rb', line 16 def publish() client.publish(channel, ) end |
- (Object) subscribe(&block)
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/faye-rails/controller/channel.rb', line 41 def subscribe(&block) EM.schedule do @subscription = FayeRails.client(endpoint).subscribe(channel) do || Message.new.tap do |m| m. = m.channel = channel m.instance_eval(&block) end end end end |
- (Object) unsubscribe
53 54 55 56 57 |
# File 'lib/faye-rails/controller/channel.rb', line 53 def unsubscribe EM.schedule do FayeRails.client(endpoint).unsubscribe(@subscription) end end |