Class: Faye::Subscription
- Inherits:
-
Object
- Object
- Faye::Subscription
- Includes:
- Deferrable
- Defined in:
- lib/faye/protocol/subscription.rb
Instance Method Summary collapse
- #call(*args) ⇒ Object
- #cancel ⇒ Object
-
#initialize(client, channels, callback) ⇒ Subscription
constructor
A new instance of Subscription.
- #to_proc ⇒ Object
- #unsubscribe ⇒ Object
- #with_channel(&callback) ⇒ Object
Methods included from Deferrable
Constructor Details
#initialize(client, channels, callback) ⇒ Subscription
Returns a new instance of Subscription.
5 6 7 8 9 10 |
# File 'lib/faye/protocol/subscription.rb', line 5 def initialize(client, channels, callback) @client = client @channels = channels @callback = callback @cancelled = false end |
Instance Method Details
#call(*args) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/faye/protocol/subscription.rb', line 17 def call(*args) = args.first @callback.call(['data']) if @callback @with_channel.call(['channel'], ['data']) if @with_channel end |
#cancel ⇒ Object
28 29 30 31 32 |
# File 'lib/faye/protocol/subscription.rb', line 28 def cancel return if @cancelled @client.unsubscribe(@channels, self) @cancelled = true end |
#to_proc ⇒ Object
24 25 26 |
# File 'lib/faye/protocol/subscription.rb', line 24 def to_proc @to_proc ||= lambda { |*a| call(*a) } end |
#unsubscribe ⇒ Object
34 35 36 |
# File 'lib/faye/protocol/subscription.rb', line 34 def unsubscribe cancel end |
#with_channel(&callback) ⇒ Object
12 13 14 15 |
# File 'lib/faye/protocol/subscription.rb', line 12 def with_channel(&callback) @with_channel = callback self end |