Class: EventflitClient::Channel
- Inherits:
-
Object
- Object
- EventflitClient::Channel
- Defined in:
- lib/eventflit-client/channel.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
-
#global ⇒ Object
Returns the value of attribute global.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#subscribed ⇒ Object
Returns the value of attribute subscribed.
-
#user_data ⇒ Object
readonly
Returns the value of attribute user_data.
Instance Method Summary collapse
- #acknowledge_subscription(data) ⇒ Object
- #bind(event_name, &callback) ⇒ Object
- #dispatch(event_name, data) ⇒ Object
- #dispatch_with_all(event_name, data) ⇒ Object
-
#initialize(channel_name, user_data = nil, logger = EventflitClient.logger) ⇒ Channel
constructor
A new instance of Channel.
Constructor Details
#initialize(channel_name, user_data = nil, logger = EventflitClient.logger) ⇒ Channel
Returns a new instance of Channel.
7 8 9 10 11 12 13 14 |
# File 'lib/eventflit-client/channel.rb', line 7 def initialize(channel_name, user_data=nil, logger=EventflitClient.logger) @name = channel_name @user_data = user_data @logger = logger @global = false @callbacks = {} @subscribed = false end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
5 6 7 |
# File 'lib/eventflit-client/channel.rb', line 5 def callbacks @callbacks end |
#global ⇒ Object
Returns the value of attribute global.
4 5 6 |
# File 'lib/eventflit-client/channel.rb', line 4 def global @global end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/eventflit-client/channel.rb', line 5 def name @name end |
#subscribed ⇒ Object
Returns the value of attribute subscribed.
4 5 6 |
# File 'lib/eventflit-client/channel.rb', line 4 def subscribed @subscribed end |
#user_data ⇒ Object (readonly)
Returns the value of attribute user_data.
5 6 7 |
# File 'lib/eventflit-client/channel.rb', line 5 def user_data @user_data end |
Instance Method Details
#acknowledge_subscription(data) ⇒ Object
38 39 40 |
# File 'lib/eventflit-client/channel.rb', line 38 def acknowledge_subscription(data) @subscribed = true end |
#bind(event_name, &callback) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/eventflit-client/channel.rb', line 16 def bind(event_name, &callback) EventflitClient.logger.debug "Binding #{event_name} to #{name}" @callbacks[event_name] = callbacks[event_name] || [] @callbacks[event_name] << callback return self end |
#dispatch(event_name, data) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/eventflit-client/channel.rb', line 27 def dispatch(event_name, data) logger.debug("Dispatching #{global ? 'global ' : ''}callbacks for #{event_name}") if @callbacks[event_name] @callbacks[event_name].each do |callback| callback.call(data) end else logger.debug "No #{global ? 'global ' : ''}callbacks to dispatch for #{event_name}" end end |
#dispatch_with_all(event_name, data) ⇒ Object
23 24 25 |
# File 'lib/eventflit-client/channel.rb', line 23 def dispatch_with_all(event_name, data) dispatch(event_name, data) end |