Class: FayeRails::Controller::Channel
- Inherits:
-
Object
- Object
- FayeRails::Controller::Channel
- Defined in:
- lib/faye-rails/controller/channel.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
- #client ⇒ Object
- #filter(direction = :any, &block) ⇒ Object
-
#initialize(channel, endpoint = nil) ⇒ Channel
constructor
A new instance of Channel.
- #monitor(event, &block) ⇒ Object
- #publish(message) ⇒ Object
- #subscribe(&block) ⇒ Object
- #unsubscribe ⇒ Object
Constructor Details
#initialize(channel, endpoint = nil) ⇒ Channel
Returns 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
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
5 6 7 |
# File 'lib/faye-rails/controller/channel.rb', line 5 def channel @channel end |
#endpoint ⇒ Object (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
#client ⇒ Object
12 13 14 |
# File 'lib/faye-rails/controller/channel.rb', line 12 def client FayeRails.client(endpoint) end |
#filter(direction = :any, &block) ⇒ Object
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 |
#monitor(event, &block) ⇒ Object
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 FayeRails::Matcher.match? channel, m.channel end end end |
#publish(message) ⇒ Object
16 17 18 |
# File 'lib/faye-rails/controller/channel.rb', line 16 def publish() client.publish(channel, ) end |