Class: Rlyeh::Session

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Celluloid, Logger
Defined in:
lib/rlyeh/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

crash, format_exception

Constructor Details

#initialize(id) ⇒ Session

Returns a new instance of Session.



15
16
17
18
19
# File 'lib/rlyeh/session.rb', line 15

def initialize(id)
  @id = id
  @connections = Set.new
  debug "Session started: #{@id}"
end

Instance Attribute Details

#connectionsObject (readonly)

Returns the value of attribute connections.



12
13
14
# File 'lib/rlyeh/session.rb', line 12

def connections
  @connections
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/rlyeh/session.rb', line 12

def id
  @id
end

Instance Method Details

#attach(connection) ⇒ Object



25
26
27
28
# File 'lib/rlyeh/session.rb', line 25

def attach(connection)
  connection.attach self
  @connections.add connection
end

#closeObject



21
22
23
# File 'lib/rlyeh/session.rb', line 21

def close
  debug "Session closed: #{@id}"
end

#detach(connection) ⇒ Object



30
31
32
33
# File 'lib/rlyeh/session.rb', line 30

def detach(connection)
  @connections.delete connection
  connection.detach self
end

#send_data(data) ⇒ Object



35
36
37
38
39
# File 'lib/rlyeh/session.rb', line 35

def send_data(data)
  @connections.each do |connection|
    connection.send_data data, false
  end
end