Class: RComet::User
- Inherits:
-
Object
- Object
- RComet::User
- Defined in:
- lib/rcomet/user.rb
Instance Attribute Summary collapse
-
#connected ⇒ Object
Returns the value of attribute connected.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#has_channel? ⇒ Boolean
:nodoc:.
-
#initialize(adapter) ⇒ User
constructor
Create a new Comet user.
-
#send(message) ⇒ Object
:nodoc:.
-
#subscribe(channel) ⇒ Object
Subscribe to a given channel.
-
#unsubscribe(channel) ⇒ Object
Unsubscribe to a given channel.
- #unsubscribe_all ⇒ Object
-
#wait(messages) ⇒ Object
:nodoc:.
Constructor Details
#initialize(adapter) ⇒ User
Create a new Comet user
7 8 9 10 11 12 13 14 15 |
# File 'lib/rcomet/user.rb', line 7 def initialize(adapter) @connected = false @id = RComet.random(64) @channels = Hash.new @event_mutex = Mutex.new = [] @adapter = adapter end |
Instance Attribute Details
#connected ⇒ Object
Returns the value of attribute connected.
4 5 6 |
# File 'lib/rcomet/user.rb', line 4 def connected @connected end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/rcomet/user.rb', line 3 def id @id end |
Instance Method Details
#has_channel? ⇒ Boolean
:nodoc:
57 58 59 |
# File 'lib/rcomet/user.rb', line 57 def has_channel? #:nodoc: return( not @channels.empty? ) end |
#send(message) ⇒ Object
:nodoc:
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rcomet/user.rb', line 27 def send( ) #:nodoc: if @connected == false ## ADD TIMEOUT ! unless @adapter.timeout.nil? @adapter.timeout.call(self) end end << @continue = false end |
#subscribe(channel) ⇒ Object
Subscribe to a given channel
40 41 42 43 |
# File 'lib/rcomet/user.rb', line 40 def subscribe( channel ) channel.add_user( self ) @channels[channel.path] = channel end |
#unsubscribe(channel) ⇒ Object
Unsubscribe to a given channel
46 47 48 49 |
# File 'lib/rcomet/user.rb', line 46 def unsubscribe( channel ) c = @channels.delete(channel) c.delete_user(self) if c end |
#unsubscribe_all ⇒ Object
51 52 53 54 55 |
# File 'lib/rcomet/user.rb', line 51 def unsubscribe_all( ) @channels.each do |c| unsubscribe(c) end end |
#wait(messages) ⇒ Object
:nodoc:
17 18 19 20 21 22 23 24 25 |
# File 'lib/rcomet/user.rb', line 17 def wait( ) #:nodoc: @continue = .empty? << while @continue; end = .clone = [] return end |